This is an archive of the discontinued LLVM Phabricator instance.

Disable ENABLE_EXPORTS for NetBSD static linking
Changes PlannedPublic

Authored by tomsun.0.7 on Jun 4 2018, 7:45 AM.

Details

Summary

When trying to build static clang with flag -DLLVM_BUILD_STATIC
for cmake, ENABLE_EXPORTS=1 will introduce -Wl,--export-dynamic
flag while linking.

With this flag, NetBSD will recognize the generated clang as
dynamically linked binary with dependency to /lib/ld64.so.1,
which does not exist. The following is the information for clang
binary:

% file clang-7
clang-7: ELF 64-bit LSB executable, x86-64, version 1 (SYSV),
dynamically linked, interpreter /lib/ld64.so.1, for NetBSD
8.99.17, not stripped
% ldd clang-7
clang-7:
// nothing else

To prevent this, this modification chooses to directly prevent
the setting of ENABLE_EXPORTS flag, but we are not sure whether
this is a proper solution.

Diff Detail

Repository
rL LLVM

Event Timeline

tomsun.0.7 created this revision.Jun 4 2018, 7:45 AM
tomsun.0.7 edited the summary of this revision. (Show Details)Jun 4 2018, 7:46 AM

+ chandlerc (CMake maintainer)
+ ruiu (lld maintainer for insight)

chandlerc requested changes to this revision.Jul 6 2018, 6:58 PM

While I understand the motivation, this is not the correct fix.

For example, this will almost certainly break the JIT unittests.

This function is designed to mutate a target such that it exports its dynamic symbols. If the linker is not doing the correct thing when we link using -Wl,--export-dynamic, then either the linker is broken or we need to customize CMake to use a different flag to the linker on NetBSD (much like we do on Apple platforms).

But the important thing is that this function still needs to serve its purpose of making the executable export dynamic symbols. You can't just turn that off silently on NetBSD -- things are actually relying on it.

This revision now requires changes to proceed.Jul 6 2018, 6:58 PM
tomsun.0.7 planned changes to this revision.Jul 7 2018, 1:29 AM

A problem is that NetBSD is probably the only mainstream OS left using gnu ld (at least for linking Clang/LLVM) and we catch issues of ld vs gold/lld on NetBSD.