[llvm] ea85391 - [COFF] Force Symbols containing '.' to be quoted

Jameson Nash via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 30 14:31:38 PDT 2021


Author: Keno Fischer
Date: 2021-08-30T17:26:57-04:00
New Revision: ea8539111d444ffb93ab09c5865d9a1a0927cb2c

URL: https://github.com/llvm/llvm-project/commit/ea8539111d444ffb93ab09c5865d9a1a0927cb2c
DIFF: https://github.com/llvm/llvm-project/commit/ea8539111d444ffb93ab09c5865d9a1a0927cb2c.diff

LOG: [COFF] Force Symbols containing '.' to be quoted

In D87099, the mangler learned to quote export directives that contain
special characters. Only alhpanumerical characters as well as
'_', '$', '.' and '@' were exmpt from this quoting. However, at least
binutils considers an unquoted '.' to be syntax and object files
containing such symbols will cause errors during linking. Fix that
by removing '.' from the list of allowed exemptions.

Differential Revision: https://reviews.llvm.org/D100359

Added: 
    

Modified: 
    llvm/lib/IR/Mangler.cpp
    llvm/test/CodeGen/X86/dllexport.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Mangler.cpp b/llvm/lib/IR/Mangler.cpp
index bbdde586e6e0..db833e3c668f 100644
--- a/llvm/lib/IR/Mangler.cpp
+++ b/llvm/lib/IR/Mangler.cpp
@@ -186,7 +186,7 @@ void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
 
 // Check if the name needs quotes to be safe for the linker to interpret.
 static bool canBeUnquotedInDirective(char C) {
-  return isAlnum(C) || C == '_' || C == '$' || C == '.' || C == '@';
+  return isAlnum(C) || C == '_' || C == '@';
 }
 
 static bool canBeUnquotedInDirective(StringRef Name) {

diff  --git a/llvm/test/CodeGen/X86/dllexport.ll b/llvm/test/CodeGen/X86/dllexport.ll
index 596fd4a3a4bd..043b18067574 100644
--- a/llvm/test/CodeGen/X86/dllexport.ll
+++ b/llvm/test/CodeGen/X86/dllexport.ll
@@ -84,6 +84,9 @@ define weak_odr dllexport void @weak1() {
 ; CHECK: .globl "_complex-name"
 @"complex-name" = dllexport global i32 1, align 4
 
+; CHECK: .globl _complex.name
+@"complex.name" = dllexport global i32 1, align 4
+
 
 ; Verify items that should not be exported do not appear in the export table.
 ; We use a separate check prefix to avoid confusion between -NOT and -SAME.
@@ -106,6 +109,7 @@ define weak_odr dllexport void @weak1() {
 ; CHECK-CL: .ascii " /EXPORT:_WeakVar1,DATA"
 ; CHECK-CL: .ascii " /EXPORT:_WeakVar2,DATA"
 ; CHECK-CL: .ascii " /EXPORT:\"_complex-name\",DATA"
+; CHECK-CL: .ascii " /EXPORT:\"_complex.name\",DATA"
 ; CHECK-CL: .ascii " /EXPORT:_alias"
 ; CHECK-CL: .ascii " /EXPORT:_alias2"
 ; CHECK-CL: .ascii " /EXPORT:_alias3"
@@ -124,6 +128,7 @@ define weak_odr dllexport void @weak1() {
 ; CHECK-GCC: .ascii " -export:WeakVar1,data"
 ; CHECK-GCC: .ascii " -export:WeakVar2,data"
 ; CHECK-GCC: .ascii " -export:\"complex-name\",data"
+; CHECK-GCC: .ascii " -export:\"complex.name\",data"
 ; CHECK-GCC: .ascii " -export:alias"
 ; CHECK-GCC: .ascii " -export:alias2"
 ; CHECK-GCC: .ascii " -export:alias3"


        


More information about the llvm-commits mailing list