[llvm] abcb3d5 - [MC][ELF] Mark GNU ABI if ifunc are used

Adhemerval Zanella via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 25 14:19:22 PDT 2022


Author: Adhemerval Zanella
Date: 2022-08-25T18:19:10-03:00
New Revision: abcb3d58d999d6325c447daf1f9b439a9f4f465d

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

LOG: [MC][ELF] Mark GNU ABI if ifunc are used

Similar to D107861.  Some tools required the GNU ABI mark to output
the symbol is a IFUNC type correctly (for instance binutils readelf).

Reviewed By: MaskRay

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

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

Modified: 
    llvm/lib/MC/MCELFStreamer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp
index ca7f28e1386e0..a79b62acde957 100644
--- a/llvm/lib/MC/MCELFStreamer.cpp
+++ b/llvm/lib/MC/MCELFStreamer.cpp
@@ -263,6 +263,7 @@ bool MCELFStreamer::emitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
 
   case MCSA_ELF_TypeIndFunction:
     Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC));
+    getAssembler().getWriter().markGnuAbi();
     break;
 
   case MCSA_ELF_TypeObject:

diff  --git a/llvm/test/MC/ELF/ifunc-gnu.s b/llvm/test/MC/ELF/ifunc-gnu.s
new file mode 100644
index 0000000000000..dd9898cb803bb
--- /dev/null
+++ b/llvm/test/MC/ELF/ifunc-gnu.s
@@ -0,0 +1,22 @@
+# REQUIRES: x86-registered-target
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux-gnu %s -o -| llvm-readelf -hs - | FileCheck %s
+
+.text
+
+.type  foo_impl, at function
+foo_impl:
+  ret
+
+.type  foo_resolver, at function
+foo_resolver:
+  mov $foo_impl, %rax
+  ret
+
+.type  foo, at gnu_indirect_function
+.set   foo,foo_resolver
+
+## ELFOSABI_NONE is changed to ELFOSABI_GNU. Other OSABI values are unchanged.
+# CHECK:      OS/ABI: UNIX - GNU
+# CHECK:      FUNC    LOCAL  DEFAULT    2 foo_impl
+# CHECK-NEXT: FUNC    LOCAL  DEFAULT    2 foo_resolver
+# CHECK-NEXT: IFUNC   LOCAL  DEFAULT    2 foo


        


More information about the llvm-commits mailing list