llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28k stars 11.56k forks source link

Regression(r309526): DWARF info may be corrupt; offsets in a range list entry are in different sections #33354

Open nico opened 7 years ago

nico commented 7 years ago
Bugzilla Link 34007
Version trunk
OS Linux
Attachments test.ii
CC @dwblaikie,@rnk

Extended Description

test.ii is cxa_default_handlers.cpp from libc++abi after preprocessing.

Compile like so:

../../llvm-build-nolibcxx/bin/clang++ -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -funwind-tables -fPIC -pipe -Bthird_party/binutils/Linux_x64/Release/bin -pthread -fcolor-diagnostics -m32 -msse2 -mfpmath=sse -mmmx -momit-leaf-frame-pointer -mstack-alignment=16 -mstackrealign -O0 -fno-omit-frame-pointer -gdwarf-3 -g2 -ggnu-pubnames -gsplit-dwarf -fvisibility=hidden -fPIC -fstrict-aliasing -std=gnu++14 -fvisibility-inlines-hidden -frtti -x c++ -c test.ii -o test.o

Then link like so:

../../llvm-build-nolibcxx/bin/clang++ -shared -Wl,--fatal-warnings -fPIC -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro -Wl,-z,defs -Wl,--no-as-needed -lpthread -Wl,--as-needed -fuse-ld=gold -Bthird_party/binutils/Linux_x64/Release/bin -nodefaultlibs -m32 -Wl,--gdb-index --sysroot=build/linux/debian_jessie_i386-sysroot test.o third_party/binutils/Linux_x64/Release/bin/ld.gold: warning: test.o: DWARF info may be corrupt; offsets in a range list entry are in different sections buildtools/third_party/libc++abi/trunk/src/cxa_default_handlers.cpp:29: error: undefined reference to 'cxa_get_globals_fast' buildtools/third_party/libc++abi/trunk/src/cxa_default_handlers.cpp:53: error: undefined reference to 'cxa_demangle' buildtools/third_party/libc++abi/trunk/src/cxa_default_handlers.cpp:0: error: undefined reference to 'typeinfo for std::exception' buildtools/third_party/libc++abi/trunk/src/cxa_default_handlers.cpp:63: error: undefined reference to 'abort_message' buildtools/third_party/libc++abi/trunk/src/cxa_default_handlers.cpp:68: error: undefined reference to 'abort_message' buildtools/third_party/libc++abi/trunk/src/cxa_default_handlers.cpp:73: error: undefined reference to 'abort_message' buildtools/third_party/libc++abi/trunk/src/cxa_default_handlers.cpp:77: error: undefined reference to 'abort_message' buildtools/third_party/libc++abi/trunk/src/cxa_default_handlers.cpp:84: error: undefined reference to 'std::terminate()' clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)

The undefined references are fine (an artifact of reducing this to one file), but the "DWARF info may be corrupt" is not good.

Download http://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/6f7741c4222de05cd5f2fbb9f02d34f76e5a3134/debian_jessie_i386_sysroot.tar.xz and extract it to build/linux/debian_jessie_i386-sysroot to get that sysroot and http://commondatastorage.googleapis.com/chromium-binutils/0cb5726d9701f8be6a81b199899de1de552922f2 and put it at third_party/binutils/Linux_x64/Release/bin to get that gold (it's I think a prebuilt of the latest stable gold, maybe with some cherry-picked patches).

dwblaikie commented 7 years ago

Here's a dodgy change but at least demonstrates that gold seems to work fine with this issue addressed:

--- ../.citc/baseline/google3/third_party/binutils/binutils/gold/dwarf_reader.cc 2017-06-22 19:38:27.000000000 -0700 +++ third_party/binutils/binutils/gold/dwarf_reader.cc 2017-07-31 16:48:58.000000000 -0700 @@ -442,12 +442,12 @@ break;

   // A "base address selection entry" is identified by
   // 0xffffffff for the first value of the pair.  The second
   // value is used as a base for subsequent range list entries.

A little above in the code the 'start' value is read as an unsigned 4 byte int, widened into an signed 8 byte int, which doesn't sign extend (since it wasn't signed).

dwblaikie commented 7 years ago

Yep, gold bug in parsing 32 bit range lists. The value in the table is read as 32 bit unsigned, widened to long, then compared to -1.

dwblaikie commented 7 years ago

Reduced to:

int a; int b = a; void d() {}

$ clang++ -g test.cpp -fuse-ld=gold -Wl,--gdb-index -m32

The debug_ranges section looks identical between 32 and 64 bit, except for the size of the entries (32 bit or 64 bit respectively)... so I sort of feel like this is probably a gold bug..

But will keep looking more closely.

dwblaikie commented 7 years ago

Disabled this behind a flag in r309630