Skip to content

A segmentation fault occurs when it compiles the UT on the arm64 platform. #30

@KindleKin

Description

@KindleKin

root@centos:/home/xxx/cpp-stub/ut_examples/gtest/ut/src# ll
total 12
drwxr-xr-x. 4 root root 87 Feb 4 07:57 ./
drwxr-xr-x. 5 root root 43 Feb 3 10:12 ../
-rw-r--r--. 1 root root 588 Feb 4 07:31 Makefile
drwxr-xr-x. 2 root root 25 Feb 4 07:57 fixtures/
-rw-r--r--. 1 root root 220 Feb 3 09:56 main.cpp
drwxr-xr-x. 2 root root 26 Feb 4 07:57 mocks/
-rw-r--r--. 1 root root 3233 Feb 4 07:27 test_obj.cpp
root@centos:/home/xxx/cpp-stub/ut_examples/gtest/ut/src# make
g++ -std=c++11 -g -no-pie -fno-stack-protector -Wall -Wno-unused-function -Wno-unused-variable -Wno-pmf-conversions -I../include -Imocks -Ifixtures -I../../src -I../../../../src -c -MMD test_obj.cpp -o test_obj.o
g++ -std=c++11 -g -no-pie -fno-stack-protector -Wall -Wno-unused-function -Wno-unused-variable -Wno-pmf-conversions -I../include -Imocks -Ifixtures -I../../src -I../../../../src -c -MMD main.cpp -o main.o
g++ -std=c++11 -g -no-pie -fno-stack-protector -Wall -Wno-unused-function -Wno-unused-variable -Wno-pmf-conversions ./test_obj.o ./main.o -L../lib -lgtest -lgmock -lm -lpthread -o ut
root@centos69203:/home/xxx/cpp-stub/ut_examples/gtest/ut/src# ./ut --gtest_filter=get_number_test.returns_correct_value
Note: Google Test filter = get_number_test.returns_correct_value
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from get_number_test
[ RUN ] get_number_test.returns_correct_value
Segmentation fault (core dumped)
root@centos:/home/xxx/cpp-stub/ut_examples/gtest/ut/src# ll
total 4340
drwxr-xr-x. 4 root root 179 Feb 4 07:58 ./
drwxr-xr-x. 5 root root 43 Feb 3 10:12 ../
-rw-r--r--. 1 root root 588 Feb 4 07:31 Makefile
-rw-------. 1 root root 2031616 Feb 4 07:58 core.90826
drwxr-xr-x. 2 root root 25 Feb 4 07:57 fixtures/
-rw-r--r--. 1 root root 220 Feb 3 09:56 main.cpp
-rw-r--r--. 1 root root 1700 Feb 4 07:58 main.d
-rw-r--r--. 1 root root 116440 Feb 4 07:58 main.o
drwxr-xr-x. 2 root root 26 Feb 4 07:57 mocks/
-rw-r--r--. 1 root root 3233 Feb 4 07:27 test_obj.cpp
-rw-r--r--. 1 root root 1850 Feb 4 07:58 test_obj.d
-rw-r--r--. 1 root root 1479800 Feb 4 07:58 test_obj.o
-rwxr-xr-x. 1 root root 844208 Feb 4 07:58 ut*
root@centos:/home/xxx/cpp-stub/ut_examples/gtest/ut/src# gdb ut core.90826
GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ut...done.
[New LWP 90826]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
Core was generated by `./ut --gtest_filter=get_number_test.returns_correct_value'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x000000000040cf88 in Stub::set<int (Obj::)(), int ()(void*)> (this=0xffffdb3e9b10, addr=&virtual Obj::get_number(), addr_stub=0x40a17c <get_number_stub(void*)>) at ../../../../src/stub.h:305

warning: Source file is more recent than executable.
305 std::memcpy(pstub->code_buf, fn, CODESIZE_MIN);
(gdb) bt
#0 0x000000000040cf88 in Stub::set<int (Obj::)(), int ()(void*)> (this=0xffffdb3e9b10, addr=&virtual Obj::get_number(), addr_stub=0x40a17c <get_number_stub(void*)>) at ../../../../src/stub.h:305
#1 0x000000000040a1cc in get_number_test_returns_correct_value_Test::TestBody (this=0x1b103450) at test_obj.cpp:75
#2 0x0000ffff7f434548 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::)(), char const) () from /usr/local/gtest/lib/libgtest.so
#3 0x0000ffff7f42dbd8 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::)(), char const) () from /usr/local/gtest/lib/libgtest.so
#4 0x0000ffff7f40c050 in testing::Test::Run() () from /usr/local/gtest/lib/libgtest.so
#5 0x0000ffff7f40c93c in testing::TestInfo::Run() () from /usr/local/gtest/lib/libgtest.so
#6 0x0000ffff7f40cff0 in testing::TestCase::Run() () from /usr/local/gtest/lib/libgtest.so
#7 0x0000ffff7f417160 in testing::internal::UnitTestImpl::RunAllTests() () from /usr/local/gtest/lib/libgtest.so
#8 0x0000ffff7f4357cc in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::)(), char const) () from /usr/local/gtest/lib/libgtest.so
#9 0x0000ffff7f42eb10 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::)(), char const) () from /usr/local/gtest/lib/libgtest.so
#10 0x0000ffff7f415ce0 in testing::UnitTest::Run() () from /usr/local/gtest/lib/libgtest.so
#11 0x00000000004182ac in RUN_ALL_TESTS () at ../include/gtest/gtest.h:2341
#12 0x0000000000418218 in main (argc=1, argv=0xffffdb3ea008) at main.cpp:12
(gdb) q
root@centos:/home/xxx/cpp-stub/ut_examples/gtest/ut/src# readelf -h ut
ELF Header:
Magic: 7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - GNU
ABI Version: 0
Type: EXEC (Executable file)
Machine: AArch64
Version: 0x1
Entry point address: 0x409e70
Start of program headers: 64 (bytes into file)
Start of section headers: 841840 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 9
Size of section headers: 64 (bytes)
Number of section headers: 37
Section header string table index: 36

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions