diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2019-08-01 01:38:53 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2019-08-01 01:38:53 +0000 |
commit | fbc563e2cb6c5f1d0200b390513506b6aca4d2e9 (patch) | |
tree | 667430752e25541f5f6a8526f962acde68a7211a /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | |
parent | d48324ff6fe77e0ef26060294905e1bc64b8535d (diff) | |
download | llvm-fbc563e2cb6c5f1d0200b390513506b6aca4d2e9.zip llvm-fbc563e2cb6c5f1d0200b390513506b6aca4d2e9.tar.gz llvm-fbc563e2cb6c5f1d0200b390513506b6aca4d2e9.tar.bz2 |
Create unique, but identically-named ELF sections for explicitly-sectioned functions and globals when using -function-sections and -data-sections.
This allows functions and globals to to be reordered later in the linking phase
(using the -symbol-ordering-file) even though reordering will be limited to
the scope of the explicit section.
Patch by Rahman Lavaee!
Differential Revision: https://reviews.llvm.org/D65478
llvm-svn: 367501
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index ac7c4c5..7a93a26 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -586,15 +586,30 @@ MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal( Flags |= ELF::SHF_GROUP; } + bool EmitUniqueSection = false; + + // If we have -ffunction-sections or -fdata-sections then we should emit the + // global value to a uniqued section of the same name. + if (!(Flags & ELF::SHF_MERGE) && !Kind.isCommon()) { + if (Kind.isText()) + EmitUniqueSection = TM.getFunctionSections(); + else + EmitUniqueSection = TM.getDataSections(); + } + EmitUniqueSection |= GO->hasComdat(); + // A section can have at most one associated section. Put each global with // MD_associated in a unique section. - unsigned UniqueID = MCContext::GenericSectionID; const MCSymbolELF *AssociatedSymbol = getAssociatedSymbol(GO, TM); if (AssociatedSymbol) { - UniqueID = NextUniqueID++; + EmitUniqueSection = true; Flags |= ELF::SHF_LINK_ORDER; } + unsigned UniqueID = MCContext::GenericSectionID; + if (EmitUniqueSection) + UniqueID = NextUniqueID++; + MCSectionELF *Section = getContext().getELFSection( SectionName, getELFSectionType(SectionName, Kind), Flags, getEntrySizeForKind(Kind), Group, UniqueID, AssociatedSymbol); |