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

SegmentFault when strip binary which is optimized by BOLT #288

Closed HShan886 closed 2 years ago

HShan886 commented 2 years ago

Hi I use latest bolt to optimize bubble_sort binary with command line llvm-bolt bubble_sort -o bubble_sort.bolt -data=perf.fdata -reorder-blocks=cache+ -reorder-functions=hfsort -split-functions=2 -split-all-cold -split-eh -dyno-stats --update-debug-sections -v=2 bubble_sort's url is https://github.com/VictorRodriguez/autofdo_tutorial and is generated by command make release

Then using the following command to strip debug information eu-strip bubble_sort.bolt -o bubble_sort.strip.bolt -f bubble_sort.sym I got a segment fault when running bubble_sort.strip.bolt. This segment fault means cannot access the new .text section.

Any suggestion will be pleasure, thank you.

yota9 commented 2 years ago

Hello @Haishan312 . Is it x86 or arm? What compiler and linker you are using? Did you pass -fno-reorder-blocks-and-partition flag?

HShan886 commented 2 years ago

@yota9 OS: x86_64 compiler: gcc-9.2.1 ld: 2.32 I pass -Wl,--emit-relocs -fno-reorder-blocks-and-partition into CFLAGS

maksfb commented 2 years ago

@Haishan312, eu-strip is likely corrupting the binary. One (hacky) workaround is to add -use-gnu-stack flag to llvm-bolt invocation, which will try to reuse the existing program header for the new segment.

yota9 commented 2 years ago

Oups didn't notice strip word, sorry :)

HShan886 commented 2 years ago

@maksfb it works, thank you.