facebookarchive / BOLT

Binary Optimization and Layout Tool - A linux command-line utility used for optimizing performance of binaries
2.52k stars 178 forks source link

DWARF: Update debug sections fails on aarch64 #275

Closed yota9 closed 2 years ago

yota9 commented 2 years ago

After the latest rebase two tests are failing:

  BOLT :: AArch64/asm-func-debug.test
  BOLT :: AArch64/update-debug-reloc.test

BOLT output:

BOLT-INFO: Target architecture: aarch64
BOLT-INFO: BOLT version: 593706c9ae131ff38dde15c3f5b1868bedb5541e
BOLT-INFO: first alloc address is 0x400000
BOLT-INFO: creating new program header table at address 0x600000, offset 0x200000
BOLT-WARNING: non-relocation mode for AArch64 is not fully supported
BOLT-INFO: disabling -align-macro-fusion on non-x86 platform
BOLT-WARNING: Ignored 0 functions due to cold fragments.
BOLT-INFO: 0 out of 12 functions in the binary (0.0%) have non-empty execution profile
BOLT-INFO: UCE removed 0 blocks and 0 bytes of code.
BOLT-INFO: Starting stub-insertion pass
BOLT-INFO: Inserted 0 stubs in the hot area and 0 stubs in the cold area. Shared 0 times, iterated 1 times.
BOLT-WARNING: unexpected low_pc form value. Cannot update DIE at offset 0x118
BOLT-WARNING: unexpected low_pc form value. Cannot update DIE at offset 0x12f
BOLT: 9 out of 12 functions were overwritten.
BOLT-INFO: setting _end to 0x60046c
#0 0x0000000001817224 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/yota9/src/llvm/build/bin/llvm-bolt+0x1817224)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /home/yota9/src/llvm/build/bin/llvm-bolt /home/yota9/src/llvm/build/tools/bolt/test/AArch64/Output/update-debug-reloc.test.tmp.exe -o /home/yota9/src/llvm/build/tools/bolt/test/AArch64/Output/update-debug-reloc.test.tmp -update-debug-sections
Segmentation fault (core dumped)

gdb:

__memcpy_generic () at ../sysdeps/aarch64/multiarch/../memcpy.S:198
198 ../sysdeps/aarch64/multiarch/../memcpy.S: No such file or directory.
(gdb) bt
#0  __memcpy_generic () at ../sysdeps/aarch64/multiarch/../memcpy.S:198
#1  0x0000fffff7d9e6a4 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long) ()
   from /lib/aarch64-linux-gnu/libstdc++.so.6
#2  0x000000000240d698 in llvm::bolt::DebugInfoBinaryPatcher::patchBinary[abi:cxx11](llvm::StringRef) ()
#3  0x000000000240d698 in llvm::bolt::DebugInfoBinaryPatcher::patchBinary[abi:cxx11](llvm::StringRef) ()
#4  0x000000000240d698 in llvm::bolt::DebugInfoBinaryPatcher::patchBinary[abi:cxx11](llvm::StringRef) ()
....

Seems to be looped in patchBinary. @ayermolo Could you please check it?

ayermolo commented 2 years ago

Clang recently switched DWARF5 by default. BOLT currently not supporting it. I am working on it, but other things keep coming up. You need to update your testing environment to force DWARF4.

yota9 commented 2 years ago

Oh I forgot about it, I thought it was fixed globally :) Thanks!

aaupov commented 2 years ago

Can you please apply -gdwarf-4 to cflags like here: https://reviews.llvm.org/D118080 and commit that?

yota9 commented 2 years ago

@aaupov Yes, sure, I will make this. I was thinking to add it to global %cflags like you did, it seems to be more right way to do this, what do you think about it? I can replace it in 5 already commited tests too if you don't mind

aaupov commented 2 years ago

@aaupov Yes, sure, I will make this. I was thinking to add it to global %cflags like you did, it seems to be more right way to do this, what do you think about it? I can replace it in 5 already commited tests too if you don't mind

I think it's the right way. I've abandoned my diff after David Blaikie pushed his fix (minutes before me), but since AArch64 tests also need fixing, let's make it right this time.