[PATCH] D46874: [MC] - Add .stack_size sections into groups and link them with .text
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 23 04:05:06 PDT 2018
grimar updated this revision to Diff 148182.
grimar added a comment.
- Do not do unification when no -ffunction-section is specified.
https://reviews.llvm.org/D46874
Files:
include/llvm/MC/MCObjectFileInfo.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/MC/MCObjectFileInfo.cpp
test/CodeGen/X86/stack-size-section2.ll
Index: test/CodeGen/X86/stack-size-section2.ll
===================================================================
--- test/CodeGen/X86/stack-size-section2.ll
+++ test/CodeGen/X86/stack-size-section2.ll
@@ -0,0 +1,29 @@
+; RUN: llc < %s -mtriple=x86_64-linux -stack-size-section -function-sections | FileCheck %s
+
+; Check we add SHF_LINK_ORDER for .stack_sizes and link it with the corresponding .text sections.
+
+; CHECK: .section .text._Z3barv,"ax", at progbits
+; CHECK: .section .stack_sizes,"o", at progbits,.text._Z3barv,unique,0
+
+; CHECK: .section .text._Z3foov,"ax", at progbits
+; CHECK: .section .stack_sizes,"o", at progbits,.text._Z3foov,unique,1
+
+; Check we add .stack_size section to COMDAT with the corresponding .text section if such COMDAT exists.
+
+; CHECK: .section .text._Z4fooTIiET_v,"axG", at progbits,_Z4fooTIiET_v,comdat
+; CHECK: .section .stack_sizes,"Go", at progbits,_Z4fooTIiET_v,comdat,.text._Z4fooTIiET_v,unique,2
+
+$_Z4fooTIiET_v = comdat any
+
+define dso_local i32 @_Z3barv() {
+ ret i32 0
+}
+
+define dso_local i32 @_Z3foov() {
+ %1 = call i32 @_Z4fooTIiET_v()
+ ret i32 %1
+}
+
+define linkonce_odr dso_local i32 @_Z4fooTIiET_v() comdat {
+ ret i32 0
+}
Index: lib/MC/MCObjectFileInfo.cpp
===================================================================
--- lib/MC/MCObjectFileInfo.cpp
+++ lib/MC/MCObjectFileInfo.cpp
@@ -948,3 +948,22 @@
return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
0, utostr(Hash));
}
+
+MCSection *MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec,
+ unsigned ID) const {
+ if (Env != IsELF)
+ return StackSizesSection;
+
+ unsigned Flags = ELF::SHF_LINK_ORDER;
+
+ StringRef GroupName;
+ const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);
+ if (const MCSymbol *Group = ElfSec.getGroup()) {
+ GroupName = Group->getName();
+ Flags |= ELF::SHF_GROUP;
+ }
+
+ const MCSymbolELF *Link = cast<MCSymbolELF>(TextSec.getBeginSymbol());
+ return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0,
+ GroupName, ID, Link);
+}
Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -989,7 +989,13 @@
if (!MF.getTarget().Options.EmitStackSizeSection)
return;
- MCSection *StackSizeSection = getObjFileLowering().getStackSizesSection();
+ // If -ffunction-section is specified, we want to emit .stack_sizes section
+ // for each .text.X section. Here we select the unique ID based on a unique
+ // function number.
+ unsigned UniqueID =
+ MF.getTarget().Options.FunctionSections ? MF.getFunctionNumber() : ~0;
+ MCSection *StackSizeSection =
+ getObjFileLowering().getStackSizesSection(*getCurrentSection(), UniqueID);
if (!StackSizeSection)
return;
Index: include/llvm/MC/MCObjectFileInfo.h
===================================================================
--- include/llvm/MC/MCObjectFileInfo.h
+++ include/llvm/MC/MCObjectFileInfo.h
@@ -299,7 +299,7 @@
MCSection *getStackMapSection() const { return StackMapSection; }
MCSection *getFaultMapSection() const { return FaultMapSection; }
- MCSection *getStackSizesSection() const { return StackSizesSection; }
+ MCSection *getStackSizesSection(const MCSection &TextSec, unsigned ID) const;
// ELF specific sections.
MCSection *getDataRelROSection() const { return DataRelROSection; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46874.148182.patch
Type: text/x-patch
Size: 3627 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180523/feeace7c/attachment.bin>
More information about the llvm-commits
mailing list