rui314 / mold

Mold: A Modern Linker 🦠
MIT License
14.43k stars 472 forks source link

Passing -static and -Wl,--dynamic-linker result in a binary that will Segmentation fault #553

Closed lancethepants closed 2 years ago

lancethepants commented 2 years ago

For my project I have several arguments in LDFLAGS including Wl,--dyanmic-linker because the root filesystem for this project lives in a non-standard directory.

https://github.com/lancethepants/tomatoware/blob/master/scripts/environment.sh#L11

On occasion I will also append -static to LDFLAGS when I want a particular binary to be built statically. Under bfd and gold this is no problem. They build the static binary and I guess just discards the Wl,--dyanmic-linker portion. With mold I will get a Segmentation fault.

readelf shows there is no dynamic section.

readelf -d binary

There is no dynamic section in this file.

file shows that it is a static binary, but also shows the interpreter which is odd. bfd & gold do not show the interpreter portion.

file binary

binary: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, interpreter /mmc/lib/ld-uClibc.so.1, stripped

lld exhibits the same behavior as mold. Will probably repot this to them as well.

I know they are conflicting arguments, but I think bfd and gold are correct to create a static binary and discard the dynamic linker bit.

MaskRay commented 2 years ago

Note: I think this works as intended, since there is no need to make -static --dynamic-linker non-orthogonal. GNU ld does have the behavior, because it uses complex conditions to decide whether PT_INTERP is created, but there is no need for behavior match in practice. Consider adding -Wl,--no-dynamic-linker explicitly.

rui314 commented 2 years ago

Closing this as working-as-intended as per @MaskRay's comment.