Skip to content

Commit aac4fe3

Browse files
rorthtstellar
authored andcommitted
[ELF] Don't emit SHF_GNU_RETAIN on Solaris
The introduction of `SHF_GNU_RETAIN` has caused massive problems on Solaris. Initially, as reported in Bug 49437, it caused dozens of testsuite failures on both sparc and x86. The objects were marked as `ELFOSABI_NONE`, but `SHF_GNU_RETAIN` is a GNU extension. In the native Solaris ABI, that flag (in the range for OS-specific values) is `SHF_SUNW_ABSENT` with a completely different semantics, which confuses Solaris `ld` very much. Later, the objects became (correctly) marked `ELFOSABI_GNU`, which Solaris `ld` doesn't support, causing it to SEGV and break the build. The linker is currently being hardened to not accept non-native OS ABIs to avoid this. The need for linker support is already documented in `clang/include/clang/Basic/AttrDocs.td`, but not currently checked. This patch avoids all this by not emitting `SHF_GNU_RETAIN` on Solaris at all. Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and `x86_64-pc-linux-gnu`. Differential Revision: https://reviews.llvm.org/D107747 (cherry picked from commit 7bbbf29)
1 parent a6c14fb commit aac4fe3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,9 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
677677
}
678678

679679
if (Retain) {
680-
if (Ctx.getAsmInfo()->useIntegratedAssembler() ||
681-
Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36))
680+
if ((Ctx.getAsmInfo()->useIntegratedAssembler() ||
681+
Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36)) &&
682+
!TM.getTargetTriple().isOSSolaris())
682683
Flags |= ELF::SHF_GNU_RETAIN;
683684
return NextUniqueID++;
684685
}
@@ -855,8 +856,10 @@ static MCSection *selectELFSectionForGlobal(
855856
EmitUniqueSection = true;
856857
Flags |= ELF::SHF_LINK_ORDER;
857858
}
858-
if (Retain && (Ctx.getAsmInfo()->useIntegratedAssembler() ||
859-
Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36))) {
859+
if (Retain &&
860+
(Ctx.getAsmInfo()->useIntegratedAssembler() ||
861+
Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36)) &&
862+
!TM.getTargetTriple().isOSSolaris()) {
860863
EmitUniqueSection = true;
861864
Flags |= ELF::SHF_GNU_RETAIN;
862865
}

0 commit comments

Comments
 (0)