[ELF] Improve the condition to create .interp
authorFangrui Song <maskray@google.com>
Mon, 3 Jun 2019 05:25:03 +0000 (05:25 +0000)
committerFangrui Song <maskray@google.com>
Thu, 26 Dec 2019 21:26:43 +0000 (13:26 -0800)
commit1417558e4a61794347c6bfbafaff7cd96985b2c3
treec18631df6893ba8d2a5b40b220ba69c86e81d48d
parentbb0138729b8d4af3d8bd888c821ff79f1350f045
[ELF] Improve the condition to create .interp

Similar to rL362355, but with the `!config->shared` guard.

(1) {gcc,clang} -fuse-ld=bfd -pie -fPIE -nostdlib a.c => .interp created
(2) {gcc,clang} -fuse-ld=lld -pie -fPIE -nostdlib a.c => .interp not created
(3) {gcc,clang} -fuse-ld=lld -pie -fPIE -nostdlib a.c a.so => .interp created

The inconsistency of (2) is due to the condition `!Config->SharedFiles.empty()`.
To make lld behave more like ld.bfd, we could change the condition to:

    config->hasDynSymTab && !config->dynamicLinker.empty() && script->needsInterpSection();

However, that would bring another inconsistency as can be observed with:

(4) {gcc,clang} -fuse-ld=bfd -no-pie -nostdlib a.c => .interp not created
lld/ELF/Writer.cpp
lld/test/ELF/dynamic-linker.s
lld/test/ELF/ppc64-func-entry-points.s