[cfe-commits] r125607 - in /cfe/trunk: lib/AST/ItaniumMangle.cpp test/CodeGen/mangle.c

Rafael Espindola rafael.espindola at gmail.com
Tue Feb 15 14:23:51 PST 2011


Author: rafael
Date: Tue Feb 15 16:23:51 2011
New Revision: 125607

URL: http://llvm.org/viewvc/llvm-project?rev=125607&view=rev
Log:
Add a hack to avoid adding '\01' to asm names when possible. It would be
better for clang to always compute the right name, but for now this hack
fixes PR9177 and lets us build firefox with LTO :-)

Modified:
    cfe/trunk/lib/AST/ItaniumMangle.cpp
    cfe/trunk/test/CodeGen/mangle.c

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=125607&r1=125606&r2=125607&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Tue Feb 15 16:23:51 2011
@@ -23,6 +23,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/Basic/ABI.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -328,7 +329,17 @@
   // over all other naming in the .o file.
   if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
     // If we have an asm name, then we use it as the mangling.
-    Out << '\01';  // LLVM IR Marker for __asm("foo")
+
+    // Adding the prefix can cause problems when one file has a "foo" and
+    // another has a "\01foo". That is known to happen on ELF with the
+    // tricks normally used for producing aliases (PR9177). Fortunately the
+    // llvm mangler on ELF is a nop, so we can just avoid adding the \01
+    // marker.
+    llvm::StringRef UserLabelPrefix =
+      getASTContext().Target.getUserLabelPrefix();
+    if (!UserLabelPrefix.empty())
+      Out << '\01';  // LLVM IR Marker for __asm("foo")
+
     Out << ALA->getLabel();
     return;
   }

Modified: cfe/trunk/test/CodeGen/mangle.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mangle.c?rev=125607&r1=125606&r2=125607&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/mangle.c (original)
+++ cfe/trunk/test/CodeGen/mangle.c Tue Feb 15 16:23:51 2011
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - %s | FileCheck %s
 
-// CHECK: @"\01foo"
+// CHECK: @foo
 
 // Make sure we mangle overloadable, even in C system headers.
 # 1 "somesystemheader.h" 1 3 4
@@ -9,7 +9,7 @@
 // CHECK: @_Z2f0l
 void __attribute__((__overloadable__)) f0(long b) {}
 
-// CHECK: @"\01bar"
+// CHECK: @bar
 
 // These should get merged.
 void foo() __asm__("bar");
@@ -55,7 +55,7 @@
 int func(void);
 extern int func (void) __asm__ ("FUNC");
 
-// CHECK: @"\01FUNC"
+// CHECK: @FUNC
 int func(void) {
   return 42;
 }





More information about the cfe-commits mailing list