[MC] Change ELFOSABI_NONE to ELFOSABI_GNU for STB_GNU_UNIQUE
authorFangrui Song <i@maskray.me>
Fri, 27 Aug 2021 15:53:55 +0000 (08:53 -0700)
committerFangrui Song <i@maskray.me>
Fri, 27 Aug 2021 15:53:55 +0000 (08:53 -0700)
Similar to D97976.
On Linux, most GCC installations are configured with
`--enable-gnu-unique-object` and such GCC emits `@gnu_unique_object` assembly.

The feature is highly controversial and disliked by many folks.
(On glibc DF_1_NODELETE is implicitly enabled and makes dlclose a no-op).

In llvm-project STB_GNU_UNIQUE is assembly only. Clang does not use STB_GNU_UNIQUE.

Use ELFOSABI_GNU to match GNU as behavior and avoid collision with other
OSABI binding values.

Reviewed By: jrtc27

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

llvm/lib/MC/MCELFStreamer.cpp
llvm/test/MC/ELF/gnu-type.s
llvm/test/MC/ELF/gnu-unique.s [new file with mode: 0644]

index 784d668..f29282f 100644 (file)
@@ -224,6 +224,7 @@ bool MCELFStreamer::emitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
   case MCSA_ELF_TypeGnuUniqueObject:
     Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
     Symbol->setBinding(ELF::STB_GNU_UNIQUE);
+    getAssembler().getWriter().markGnuAbi();
     break;
 
   case MCSA_Global:
index 19029e4..9494b7d 100644 (file)
 
        .type string_type, "function"
 // CHECK: .type string_type,@function
-
-       .type special gnu_unique_object
-// CHECK: .type special,@gnu_unique_object
-
-       .type comma_special, gnu_unique_object
-// CHECK: .type comma_special,@gnu_unique_object
-
diff --git a/llvm/test/MC/ELF/gnu-unique.s b/llvm/test/MC/ELF/gnu-unique.s
new file mode 100644 (file)
index 0000000..8948b33
--- /dev/null
@@ -0,0 +1,13 @@
+# RUN: llvm-mc -triple=x86_64 %s | FileCheck %s --check-prefix=ASM
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s | llvm-readelf -h -s - | FileCheck %s --check-prefix=OBJ
+
+# ASM: .type unique,@gnu_unique_object
+
+# OBJ: OS/ABI: UNIX - GNU
+# OBJ: Type   Bind   Vis     Ndx Name
+# OBJ: OBJECT UNIQUE DEFAULT [[#]] unique
+
+.data
+.globl unique
+.type unique, @gnu_unique_object
+unique: