This is an archive of the discontinued LLVM Phabricator instance.

ld.lld: Respect LDEMULATION environment variable.
AbandonedPublic

Authored by shlevy on May 4 2022, 12:20 PM.

Details

Reviewers
MaskRay
ruiu

Diff Detail

Event Timeline

shlevy created this revision.May 4 2022, 12:20 PM
Herald added a project: Restricted Project. · View Herald Transcript
shlevy requested review of this revision.May 4 2022, 12:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2022, 12:20 PM
shlevy added a reviewer: ruiu.May 4 2022, 12:22 PM

I've tested this manually but haven't yet set up the repo testsuite locally.

MaskRay added a comment.EditedMay 4 2022, 12:35 PM

GNU ld appears to have such a behavior but I am not sure ld.lld ever has a need for this.
In addition, ld.lld doesn't support various emulations available in ld.bfd but we seem to live well without that.
The inferred default emulation seems to work in almost all cases.

MaskRay requested changes to this revision.May 4 2022, 12:35 PM
This revision now requires changes to proceed.May 4 2022, 12:35 PM
shlevy added a comment.May 4 2022, 1:01 PM

@MaskRay The use case which led to this for me is building gmp. Its configure script uses ld --help to look for the auto-import string to determine if the linker supports shared linking, which doesn't work as the linker defaults to the elf driver. With this patch, I can just set LDEMULATION for the build and have configure detect correctly.

shlevy added a comment.May 4 2022, 1:02 PM

Note that in nixpkgs we already do set LDEMULATION in our builds, it's just been ignored by lld up until now.

@MaskRay The use case which led to this for me is building gmp. Its configure script uses ld --help to look for the auto-import string to determine if the linker supports shared linking, which doesn't work as the linker defaults to the elf driver. With this patch, I can just set LDEMULATION for the build and have configure detect correctly.

FWIW the default build of gmp works with lld and that's many distributions are already using.
If there is a missing feature, ISTM the right way is to fix the gmp build system.
Many linkers don't have the emulation concept of GNU ld. They just provide some simulation and that simulation works quite well in practice (tens of thousands of FreeBSD / Gentoo packages are buildable without LDEMULATION).

shlevy abandoned this revision.May 4 2022, 3:12 PM

Ah to be clear I only see this issue when cross-compiling to Windows with shared libs. I'd be curious to see how other setups are successfully doing that with gmp's build system.

Anyway will close if this is not wanted.