[PATCH] D65478: Create unique, but identically-named ELF sections for explicitly-sectioned functions when using -function-sections.
Rahman Lavaee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 30 14:25:32 PDT 2019
rahmanl created this revision.
rahmanl added reviewers: eugenis, tmsriram.
rahmanl added a project: LLVM.
Herald added a subscriber: llvm-commits.
This allows functions 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.
Repository:
rL LLVM
https://reviews.llvm.org/D65478
Files:
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
test/CodeGen/X86/explicit-function-sections.ll
Index: test/CodeGen/X86/explicit-function-sections.ll
===================================================================
--- /dev/null
+++ test/CodeGen/X86/explicit-function-sections.ll
@@ -0,0 +1,24 @@
+; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections | FileCheck %s -check-prefix=FSECTIONS
+; RUN: llc < %s -mtriple=x86_64-pc-linux | FileCheck %s -check-prefix=NOFSECTIONS
+
+define void @f() section "special_section" {
+ ret void
+}
+define void @g() section "special_section" {
+ ret void
+}
+
+; NOFSECTIONS: .section special_section,"ax", at progbits
+; NOFSECTIONS-NOT: section
+; NOFSECTIONS: f:
+; NOFSECTIONS-NOT: section
+; NOFSECTIONS: g:
+
+; FSECTIONS: .section special_section,"ax", at progbits
+; FSECTIONS-NOT: section
+; FSECTIONS: f:
+; FSECTIONS: .section special_section,"ax", at progbits
+; FSECTIONS-NOT: section
+; FSECTIONS: g:
+
+
Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -593,6 +593,10 @@
if (AssociatedSymbol) {
UniqueID = NextUniqueID++;
Flags |= ELF::SHF_LINK_ORDER;
+ } else if(F && TM.getFunctionSections()){
+ // Also, if -ffunction-sections is used and the global is a function, then
+ // emit a unique section.
+ UniqueID = NextUniqueID++;
}
MCSectionELF *Section = getContext().getELFSection(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65478.212437.patch
Type: text/x-patch
Size: 1457 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190730/3ebf5a27/attachment.bin>
More information about the llvm-commits
mailing list