-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Stripping BOLTed binaries may result in misaligned PT_LOADs #56738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@llvm/issue-subscribers-bolt |
@amharc, do you consider it to be an |
I'm not actually sure: on one hand, my system's version of GNU binutils
and I wasn't able to find a conclusive reference documenting what a strip tool should do in such a case, and making But on the other hand a reasonable solution would indeed be to teach |
Although this appears to work fine, this might not be a good idea until upstream llvm fixes bug [56738](llvm/llvm-project#56738). The llvm/clang build instructions have been updated to use 'ninja -j4 install' instead of 'ninja -j4 install/strip'.
@llvm/issue-subscribers-tools-llvm-objcopy-strip Author: Krzysztof Pszeniczny (amharc)
Consider the following simple `main.cc` file:
```c++
int main() {}
```
Running: $ clang++ main.cc -o main -Wl,-q
$ llvm-bolt main -o main.bolted
$ llvm-strip -S main.bolted -o main.bolted.stripped Results in a misaligned Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
...
LOAD 0x003028 0x0000000000200000 0x0000000000200000 0x200384 0x200384 R E 0x200000 which leads to program crashes at startup: $ ./main.bolted.stripped
[1] 153575 segmentation fault ./main.bolted.stripped
$ /lib64/ld-linux-x86-64.so.2 ./main.bolted.stripped
./main.bolted.stripped: error while loading shared libraries: ./main.bolted.stripped: ELF load command address/offset not properly aligned This is because the new $ llvm-readelf -l -h main.bolted
...
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x200000 0x0000000000200000 0x0000000000200000 0x000310 0x000310 R 0x8
...
LOAD 0x200000 0x0000000000200000 0x0000000000200000 0x200384 0x200384 R E 0x200000 Which confuses |
What version of llvm-strip are you using? There was a commit about 8 months ago to the LLVM main branch (so should be in the most recent release, I believe) that should address this issue, if I understand it correctly. |
Is this issue (and duplicate #89336) still relevant, after this gnu strip patch? |
GNU strip is a different tool to llvm-strip (although they parallel each other), so patches to GNU strip have no bearing on issues against llvm-strip. That being said, given my investigation and @glyh's comment later on, I think this ticket should be closed, since the issue has already been fixed, it seems. |
Consider the following simple
main.cc
file:Running:
Results in a misaligned
PT_LOAD
:which leads to program crashes at startup:
This is because the new
PT_PHDR
header was placed at the same offset as the newPT_LOAD
containing the modified.text
section:Which confuses
llvm-strip
, as it thinks that thePT_LOAD
is a child of thePT_PHDR
and thus it will disregard the alignment requirements of the (alleged) child.The text was updated successfully, but these errors were encountered: