Fix logic for not emitting no-dead-strip for some
authorDale Johannesen <dalej@apple.com>
Tue, 9 Sep 2008 01:21:22 +0000 (01:21 +0000)
committerDale Johannesen <dalej@apple.com>
Tue, 9 Sep 2008 01:21:22 +0000 (01:21 +0000)
objects in llvm.used (thanks Anton).  Makes visible
the magic 'l' prefix for symbols on Darwin which are
to be passed through the assembler, then removed at
linktime (previously all references to this had been
hidden in the ObjC FE code, oh well).

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

include/llvm/Target/TargetAsmInfo.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/Target/ARM/ARMTargetAsmInfo.cpp
lib/Target/PowerPC/PPCTargetAsmInfo.cpp
lib/Target/TargetAsmInfo.cpp
lib/Target/X86/X86TargetAsmInfo.cpp

index ff2491e7ab322dc689e2734c0c7195fa2c2a71ef..bbb58527eb620e46202554ca9270b9ae46cb430e 100644 (file)
@@ -216,10 +216,15 @@ namespace llvm {
     const char *GlobalPrefix;             // Defaults to ""
 
     /// PrivateGlobalPrefix - This prefix is used for globals like constant
-    /// pool entries that are completely private to the .o file and should not
+    /// pool entries that are completely private to the .s file and should not
     /// have names in the .o file.  This is often "." or "L".
     const char *PrivateGlobalPrefix;      // Defaults to "."
     
+    /// LessPrivateGlobalPrefix - This prefix is used for some Objective C
+    /// metadata symbols that should be passed through the assembler but be
+    /// removed by the linker.  This is "l" on Darwin.
+    const char *LessPrivateGlobalPrefix;      // Defaults to ""
+    
     /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
     /// emitted before jump tables with the specified prefix.
     const char *JumpTableSpecialLabelPrefix;  // Default to null.
@@ -653,6 +658,9 @@ namespace llvm {
     const char *getPrivateGlobalPrefix() const {
       return PrivateGlobalPrefix;
     }
+    const char *getLessPrivateGlobalPrefix() const {
+      return LessPrivateGlobalPrefix;
+    }
     const char *getJumpTableSpecialLabelPrefix() const {
       return JumpTableSpecialLabelPrefix;
     }
index 273253ae23c676dcefe761421c776e56281e7e7a..f041f3be56fcf32684c4290f339dcfc907aa1c0b 100644 (file)
@@ -452,7 +452,9 @@ const GlobalValue * AsmPrinter::findGlobalValue(const Constant *CV) {
 
 /// EmitLLVMUsedList - For targets that define a TAI::UsedDirective, mark each
 /// global in the specified llvm.used list as being used with this directive.
-/// Non-globals (i.e. internal linkage) should not be emitted.
+/// Internally linked data beginning with the PrivateGlobalPrefix or the
+/// LessPrivateGlobalPrefix does not have the directive emitted (this 
+/// occurs in ObjC metadata).
 void AsmPrinter::EmitLLVMUsedList(Constant *List) {
   const char *Directive = TAI->getUsedDirective();
 
@@ -462,7 +464,17 @@ void AsmPrinter::EmitLLVMUsedList(Constant *List) {
   
   for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
     const GlobalValue *GV = findGlobalValue(InitList->getOperand(i));
-    if (GV && (!GV->hasInternalLinkage() || isa<Function>(GV))) {
+    if (GV) {
+      if (GV->hasInternalLinkage() && !isa<Function>(GV) &&
+          ((strlen(TAI->getPrivateGlobalPrefix()) != 0 &&
+            Mang->getValueName(GV)
+              .substr(0,strlen(TAI->getPrivateGlobalPrefix())) ==
+              TAI->getPrivateGlobalPrefix()) ||
+           (strlen(TAI->getLessPrivateGlobalPrefix()) != 0 &&
+            Mang->getValueName(GV)
+              .substr(0,strlen(TAI->getLessPrivateGlobalPrefix())) ==
+              TAI->getLessPrivateGlobalPrefix())))
+        continue;
       O << Directive;
       EmitConstantValueOnly(InitList->getOperand(i));
       O << '\n';
index 3e057359582e30f5b1fbed83867013a58edbf3c6..a1a00a2cdaed1dd56ae57f6002f9ff0f852e8bdc 100644 (file)
@@ -62,6 +62,7 @@ ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMTargetMachine &TM):
 
   GlobalPrefix = "_";
   PrivateGlobalPrefix = "L";
+  LessPrivateGlobalPrefix = "l";
   StringConstantPrefix = "\1LC";
   BSSSection = 0;                       // no BSS section
   ZeroDirective = "\t.space\t";
index 1b8c1a5fb3c5ee8538dfec80fc5e4ba58f8177af..fc98e57c82a204cd5df6bb2958c5f55f0e9e43a5 100644 (file)
@@ -38,6 +38,7 @@ PPCDarwinTargetAsmInfo::PPCDarwinTargetAsmInfo(const PPCTargetMachine &TM):
   CommentString = ";";
   GlobalPrefix = "_";
   PrivateGlobalPrefix = "L";
+  LessPrivateGlobalPrefix = "l";
   StringConstantPrefix = "\1LC";
   ConstantPoolSection = "\t.const\t";
   JumpTableDataSection = ".const";
index 6baebd0ffe767236bda39befc4bd79d02bdf90dc..06b77dd26aa294e9b29bb26712942a25a568ed7d 100644 (file)
@@ -50,6 +50,7 @@ TargetAsmInfo::TargetAsmInfo() :
   CommentString("#"),
   GlobalPrefix(""),
   PrivateGlobalPrefix("."),
+  LessPrivateGlobalPrefix(""),
   JumpTableSpecialLabelPrefix(0),
   GlobalVarAddrPrefix(""),
   GlobalVarAddrSuffix(""),
index be390c239632d5922132ca5b4d7fd5bb096604c5..64858f89bd5b5dc22fde1560ffe45105997a1f44 100644 (file)
@@ -136,6 +136,7 @@ X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM):
     Data64bitsDirective = 0;       // we can't emit a 64-bit unit
   ZeroDirective = "\t.space\t";  // ".space N" emits N zeros.
   PrivateGlobalPrefix = "L";     // Marker for constant pool idxs
+  LessPrivateGlobalPrefix = "l";  // Marker for some ObjC metadata
   BSSSection = 0;                       // no BSS section.
   ZeroFillDirective = "\t.zerofill\t";  // Uses .zerofill
   if (DTM->getRelocationModel() != Reloc::Static)