Avoid an infinite cycle with private linkage and -f{data|function}-sections.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 19 Feb 2014 01:28:30 +0000 (01:28 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 19 Feb 2014 01:28:30 +0000 (01:28 +0000)
When outputting an object we check its section to find its name, but when
looking for the section with -ffunction-section we look for the symbol name.

Break the loop by requesting a name with the private prefix when constructing
the section name. This matches the behavior before r201608.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201622 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetLowering.h
lib/CodeGen/TargetLoweringBase.cpp
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
test/CodeGen/X86/global-sections.ll

index d9db22ba1e19fcf8be280c61ad3c592f331317ec..155bb0a7a58cd28b1a1ed8f8f92582e7c19f1a74 100644 (file)
@@ -1338,7 +1338,7 @@ public:
   }
 
   void getNameWithPrefix(SmallVectorImpl<char> &Name, const GlobalValue *GV,
-                         Mangler &Mang) const;
+                         Mangler &Mang, bool MayAlwaysUsePrivate = false) const;
   MCSymbol *getSymbol(const GlobalValue *GV, Mangler &Mang) const;
 
 private:
index a0ea3b3ba3b9dba15e0304b6222c9f2d4ec55a84..d3c42be5e6c951899e609db6af5ff8c931a35025 100644 (file)
@@ -1431,8 +1431,9 @@ bool TargetLoweringBase::isLegalAddressingMode(const AddrMode &AM,
 
 void TargetLoweringBase::getNameWithPrefix(SmallVectorImpl<char> &Name,
                                            const GlobalValue *GV,
-                                           Mangler &Mang) const {
-  if (!GV->hasPrivateLinkage()) {
+                                           Mangler &Mang,
+                                           bool MayAlwaysUsePrivate) const {
+  if (MayAlwaysUsePrivate || !GV->hasPrivateLinkage()) {
     // Simple case: If GV is not private, it is not important to find out if
     // private labels are legal in this case or not.
     Mang.getNameWithPrefix(Name, GV, false);
index 1bb483f0157f02f82c374d020da095ae0aa5eba5..bd54a871ca3cedf0d38eff3792c4dc6e4f353dd0 100644 (file)
@@ -248,12 +248,12 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
     Prefix = getSectionPrefixForGlobal(Kind);
 
     SmallString<128> Name(Prefix, Prefix+strlen(Prefix));
-    MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
-    Name.append(Sym->getName().begin(), Sym->getName().end());
+    TM.getTargetLowering()->getNameWithPrefix(Name, GV, Mang, true);
+
     StringRef Group = "";
     unsigned Flags = getELFSectionFlags(Kind);
     if (GV->isWeakForLinker()) {
-      Group = Sym->getName();
+      Group = Name.substr(strlen(Prefix));
       Flags |= ELF::SHF_GROUP;
     }
 
index eaf7337214b914f3fe95ba682a0ec839b4e8d414..c031821f9a6e3b268df8cc9271924eb289eb016b 100644 (file)
 ; DARWIN: .zerofill __DATA,__common,_G12,1,3
 ; DARWIN: .globl _G13
 ; DARWIN: .zerofill __DATA,__common,_G13,1,3
+
+@G14 = private unnamed_addr constant [4 x i8] c"foo\00", align 1
+
+; LINUX-SECTIONS:        .type   .LG14,@object           # @G14
+; LINUX-SECTIONS:        .section        .rodata..LG14,"aMS",@progbits,1
+; LINUX-SECTIONS: .LG14:
+; LINUX-SECTIONS:        .asciz  "foo"
+; LINUX-SECTIONS:        .size   .LG14, 4