[llvm] 83dfa0d - [MC] Change ELFOSABI_NONE to ELFOSABI_GNU for STB_GNU_UNIQUE

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 27 08:53:59 PDT 2021


Author: Fangrui Song
Date: 2021-08-27T08:53:55-07:00
New Revision: 83dfa0d098f3176607aecea815eb87979953cdb5

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

LOG: [MC] Change ELFOSABI_NONE to ELFOSABI_GNU for STB_GNU_UNIQUE

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

Added: 
    llvm/test/MC/ELF/gnu-unique.s

Modified: 
    llvm/lib/MC/MCELFStreamer.cpp
    llvm/test/MC/ELF/gnu-type.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp
index 784d66805d63..f29282ff705a 100644
--- a/llvm/lib/MC/MCELFStreamer.cpp
+++ b/llvm/lib/MC/MCELFStreamer.cpp
@@ -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:

diff  --git a/llvm/test/MC/ELF/gnu-type.s b/llvm/test/MC/ELF/gnu-type.s
index 19029e48ee96..9494b7dac58f 100644
--- a/llvm/test/MC/ELF/gnu-type.s
+++ b/llvm/test/MC/ELF/gnu-type.s
@@ -29,10 +29,3 @@
 
 	.type string_type, "function"
 // CHECK: .type string_type, at function
-
-	.type special gnu_unique_object
-// CHECK: .type special, at gnu_unique_object
-
-	.type comma_special, gnu_unique_object
-// CHECK: .type comma_special, at 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
index 000000000000..8948b33b9afb
--- /dev/null
+++ b/llvm/test/MC/ELF/gnu-unique.s
@@ -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, at 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:


        


More information about the llvm-commits mailing list