[llvm] f554e27 - [AsmPrinter] Omit unique ID for __patchable_function_entries sections

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 14 20:56:18 PST 2020


Author: Fangrui Song
Date: 2020-02-14T20:54:54-08:00
New Revision: f554e27224b9fd888d5c803e555425076d5a8c1a

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

LOG: [AsmPrinter] Omit unique ID for __patchable_function_entries sections

Follow-up for D74006.

When the integrated assembler is used, we use SHF_LINK_ORDER.  The
linked-to symbol is part of ELFSectionKey, thus we can omit the unique
ID.

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/AsmPrinter.h
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
    llvm/test/CodeGen/AArch64/patchable-function-entry.ll
    llvm/test/CodeGen/X86/patchable-function-entry-ibt.ll
    llvm/test/CodeGen/X86/patchable-function-entry.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h
index 0d3e1cf33f1f..dce2324a2b44 100644
--- a/llvm/include/llvm/CodeGen/AsmPrinter.h
+++ b/llvm/include/llvm/CodeGen/AsmPrinter.h
@@ -298,7 +298,6 @@ class AsmPrinter : public MachineFunctionPass {
   /// Emit a table with all XRay instrumentation points.
   void emitXRayTable();
 
-  DenseMap<const MCSection *, unsigned> PatchableFunctionEntryID;
   void emitPatchableFunctionEntries();
 
   //===------------------------------------------------------------------===//

diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 261bdcaa4fa7..4b5d8d4cc141 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -3262,29 +3262,22 @@ void AsmPrinter::emitPatchableFunctionEntries() {
   const unsigned PointerSize = getPointerSize();
   if (TM.getTargetTriple().isOSBinFormatELF()) {
     auto Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC;
+    const MCSymbolELF *LinkedToSym = nullptr;
+    StringRef GroupName;
 
-    // As of binutils 2.33, GNU as does not support section flag "o" or linkage
-    // field "unique". Use SHF_LINK_ORDER if we are using the integrated
-    // assembler.
+    // GNU as < 2.35 did not support section flag 'o'. Use SHF_LINK_ORDER only
+    // if we are using the integrated assembler.
     if (MAI->useIntegratedAssembler()) {
       Flags |= ELF::SHF_LINK_ORDER;
-      std::string GroupName;
       if (F.hasComdat()) {
         Flags |= ELF::SHF_GROUP;
-        GroupName = std::string(F.getComdat()->getName());
+        GroupName = F.getComdat()->getName();
       }
-      MCSection *Section = getObjFileLowering().SectionForGlobal(&F, TM);
-      unsigned UniqueID =
-          PatchableFunctionEntryID
-              .try_emplace(Section, PatchableFunctionEntryID.size())
-              .first->second;
-      OutStreamer->SwitchSection(OutContext.getELFSection(
-          "__patchable_function_entries", ELF::SHT_PROGBITS, Flags, 0,
-          GroupName, UniqueID, cast<MCSymbolELF>(CurrentFnSym)));
-    } else {
-      OutStreamer->SwitchSection(OutContext.getELFSection(
-          "__patchable_function_entries", ELF::SHT_PROGBITS, Flags));
+      LinkedToSym = cast<MCSymbolELF>(CurrentFnSym);
     }
+    OutStreamer->SwitchSection(OutContext.getELFSection(
+        "__patchable_function_entries", ELF::SHT_PROGBITS, Flags, 0, GroupName,
+        MCSection::NonUniqueID, LinkedToSym));
     emitAlignment(Align(PointerSize));
     OutStreamer->emitSymbolValue(CurrentPatchableFunctionEntrySym, PointerSize);
   }

diff  --git a/llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll b/llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
index e86ffe01b4e4..4d55eb8bb7d2 100644
--- a/llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
+++ b/llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
@@ -1,4 +1,4 @@
-; RUN: llc -mtriple=aarch64 %s -o - | FileCheck --check-prefixes=CHECK %s
+; RUN: llc -mtriple=aarch64 %s -o - | FileCheck %s
 
 define void @f0() "patchable-function-entry"="0" "branch-target-enforcement" {
 ; CHECK-LABEL: f0:
@@ -21,7 +21,7 @@ define void @f1() "patchable-function-entry"="1" "branch-target-enforcement" {
 ; CHECK-NEXT: .Lpatch0:
 ; CHECK-NEXT:  nop
 ; CHECK-NEXT:  ret
-; CHECK:      .section __patchable_function_entries,"awo", at progbits,f1,unique,0
+; CHECK:      .section __patchable_function_entries,"awo", at progbits,f1{{$}}
 ; CHECK-NEXT: .p2align 3
 ; CHECK-NEXT: .xword .Lpatch0
   ret void
@@ -41,7 +41,7 @@ define void @f2_1() "patchable-function-entry"="1" "patchable-function-prefix"="
 ; CHECK-NEXT:  ret
 ; CHECK:      .Lfunc_end2:
 ; CHECK-NEXT: .size f2_1, .Lfunc_end2-f2_1
-; CHECK:      .section __patchable_function_entries,"awo", at progbits,f2_1,unique,0
+; CHECK:      .section __patchable_function_entries,"awo", at progbits,f2_1{{$}}
 ; CHECK-NEXT: .p2align 3
 ; CHECK-NEXT: .xword .Ltmp0
   ret void
@@ -58,7 +58,7 @@ define internal void @f1i(i64 %v) "patchable-function-entry"="1" "branch-target-
 ;; Other basic blocks have BTI, but they don't affect our decision to not create .Lpatch0
 ; CHECK:      .LBB{{.+}} // %sw.bb1
 ; CHECK-NEXT:  hint #36
-; CHECK:      .section __patchable_function_entries,"awo", at progbits,f1i,unique,0
+; CHECK:      .section __patchable_function_entries,"awo", at progbits,f1i{{$}}
 ; CHECK-NEXT: .p2align 3
 ; CHECK-NEXT: .xword .Lfunc_begin3
 entry:

diff  --git a/llvm/test/CodeGen/AArch64/patchable-function-entry.ll b/llvm/test/CodeGen/AArch64/patchable-function-entry.ll
index 71b3f67e9a6f..2d5615678d8c 100644
--- a/llvm/test/CodeGen/AArch64/patchable-function-entry.ll
+++ b/llvm/test/CodeGen/AArch64/patchable-function-entry.ll
@@ -1,9 +1,9 @@
-; RUN: llc -mtriple=aarch64 %s -o - | FileCheck --check-prefixes=CHECK,NOFSECT %s
-; RUN: llc -mtriple=aarch64 -function-sections %s -o - | FileCheck --check-prefixes=CHECK,FSECT %s
+; RUN: llc -mtriple=aarch64 %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64 -function-sections %s -o - | FileCheck %s
 ; RUN: llc -mtriple=aarch64 -no-integrated-as %s -o - | FileCheck --check-prefix=NOLINK %s
 
+;; GNU as < 2.35 did not support section flag 'o'.
 ; NOLINK-NOT: "awo"
-; NOLINK-NOT: ,unique,0
 
 define i32 @f0() "patchable-function-entry"="0" {
 ; CHECK-LABEL: f0:
@@ -19,7 +19,7 @@ define i32 @f1() "patchable-function-entry"="1" {
 ; CHECK-NEXT: .Lfunc_begin1:
 ; CHECK:       nop
 ; CHECK-NEXT:  mov w0, wzr
-; CHECK:       .section __patchable_function_entries,"awo", at progbits,f1,unique,0
+; CHECK:       .section __patchable_function_entries,"awo", at progbits,f1{{$}}
 ; CHECK-NEXT:  .p2align 3
 ; CHECK-NEXT:  .xword .Lfunc_begin1
   ret i32 0
@@ -34,8 +34,7 @@ define void @f2() "patchable-function-entry"="2" {
 ; CHECK-NEXT: .Lfunc_begin2:
 ; CHECK-COUNT-2: nop
 ; CHECK-NEXT:  ret
-; NOFSECT:     .section __patchable_function_entries,"awo", at progbits,f2,unique,0
-; FSECT:       .section __patchable_function_entries,"awo", at progbits,f2,unique,1
+; CHECK:       .section __patchable_function_entries,"awo", at progbits,f2{{$}}
 ; CHECK-NEXT:  .p2align 3
 ; CHECK-NEXT:  .xword .Lfunc_begin2
   ret void
@@ -47,8 +46,7 @@ define void @f3() "patchable-function-entry"="3" comdat {
 ; CHECK-NEXT: .Lfunc_begin3:
 ; CHECK-COUNT-3: nop
 ; CHECK-NEXT:  ret
-; NOFSECT:     .section __patchable_function_entries,"aGwo", at progbits,f3,comdat,f3,unique,1
-; FSECT:       .section __patchable_function_entries,"aGwo", at progbits,f3,comdat,f3,unique,2
+; CHECK:       .section __patchable_function_entries,"aGwo", at progbits,f3,comdat,f3{{$}}
 ; CHECK-NEXT:  .p2align 3
 ; CHECK-NEXT:  .xword .Lfunc_begin3
   ret void
@@ -60,8 +58,7 @@ define void @f5() "patchable-function-entry"="5" comdat {
 ; CHECK-NEXT: .Lfunc_begin4:
 ; CHECK-COUNT-5: nop
 ; CHECK-NEXT:  sub sp, sp, #16
-; NOFSECT      .section __patchable_function_entries,"aGwo", at progbits,f5,comdat,f5,unique,2
-; FSECT:       .section __patchable_function_entries,"aGwo", at progbits,f5,comdat,f5,unique,3
+; CHECK:       .section __patchable_function_entries,"aGwo", at progbits,f5,comdat,f5{{$}}
 ; CHECK:       .p2align 3
 ; CHECK-NEXT:  .xword .Lfunc_begin4
   %frame = alloca i8, i32 16
@@ -82,8 +79,7 @@ define void @f3_2() "patchable-function-entry"="1" "patchable-function-prefix"="
 ;; .size does not include the prefix.
 ; CHECK:      .Lfunc_end5:
 ; CHECK-NEXT: .size f3_2, .Lfunc_end5-f3_2
-; NOFSECT:    .section __patchable_function_entries,"awo", at progbits,f3_2,unique,0
-; FSECT:      .section __patchable_function_entries,"awo", at progbits,f3_2,unique,4
+; CHECK:      .section __patchable_function_entries,"awo", at progbits,f3_2{{$}}
 ; CHECK:      .p2align 3
 ; CHECK-NEXT: .xword .Ltmp1
   ret void
@@ -97,8 +93,7 @@ define void @prefix() "patchable-function-entry"="0" "patchable-function-prefix"
 ; CHECK:       nop
 ; CHECK-NEXT: prefix:
 ;; Emit a __patchable_function_entries entry even if "patchable-function-entry" is 0.
-; NOFSECT     .section __patchable_function_entries,"awo", at progbits,prefix,unique,0
-; FSECT:      .section __patchable_function_entries,"awo", at progbits,prefix,unique,5
+; CHECK:      .section __patchable_function_entries,"awo", at progbits,prefix{{$}}
 ; CHECK:      .p2align 3
 ; CHECK-NEXT: .xword .Ltmp2
   ret void

diff  --git a/llvm/test/CodeGen/X86/patchable-function-entry-ibt.ll b/llvm/test/CodeGen/X86/patchable-function-entry-ibt.ll
index e74e87f49123..2cd796190c0d 100644
--- a/llvm/test/CodeGen/X86/patchable-function-entry-ibt.ll
+++ b/llvm/test/CodeGen/X86/patchable-function-entry-ibt.ll
@@ -27,7 +27,7 @@ define void @f1() "patchable-function-entry"="1" {
 ; CHECK-NEXT: .Lpatch0:
 ; CHECK-NEXT:  nop
 ; CHECK-NEXT:  ret
-; CHECK:      .section __patchable_function_entries,"awo", at progbits,f1,unique,0
+; CHECK:      .section __patchable_function_entries,"awo", at progbits,f1{{$}}
 ; 32-NEXT:    .p2align 2
 ; 32-NEXT:    .long .Lpatch0
 ; 64-NEXT:    .p2align 3
@@ -50,7 +50,7 @@ define void @f2_1() "patchable-function-entry"="1" "patchable-function-prefix"="
 ; CHECK-NEXT:  ret
 ; CHECK:      .Lfunc_end2:
 ; CHECK-NEXT: .size f2_1, .Lfunc_end2-f2_1
-; CHECK:      .section __patchable_function_entries,"awo", at progbits,f2_1,unique,0
+; CHECK:      .section __patchable_function_entries,"awo", at progbits,f2_1{{$}}
 ; 32-NEXT:    .p2align 2
 ; 32-NEXT:    .long .Ltmp0
 ; 64-NEXT:    .p2align 3
@@ -73,7 +73,7 @@ define internal void @f1i() "patchable-function-entry"="1" {
 ; CHECK-NOT:  .Lpatch0:
 ;; Another basic block has ENDBR, but it doesn't affect our decision to not create .Lpatch0
 ; CHECK:       endbr
-; CHECK:      .section __patchable_function_entries,"awo", at progbits,f1i,unique,0
+; CHECK:      .section __patchable_function_entries,"awo", at progbits,f1i{{$}}
 ; 32-NEXT:    .p2align 2
 ; 32-NEXT:    .long .Lfunc_begin3
 ; 64-NEXT:    .p2align 3

diff  --git a/llvm/test/CodeGen/X86/patchable-function-entry.ll b/llvm/test/CodeGen/X86/patchable-function-entry.ll
index 004768765017..9be41f256fd5 100644
--- a/llvm/test/CodeGen/X86/patchable-function-entry.ll
+++ b/llvm/test/CodeGen/X86/patchable-function-entry.ll
@@ -1,6 +1,6 @@
-; RUN: llc -mtriple=i386 %s -o - | FileCheck --check-prefixes=CHECK,NOFSECT,32 %s
-; RUN: llc -mtriple=x86_64 %s -o - | FileCheck --check-prefixes=CHECK,NOFSECT,64 %s
-; RUN: llc -mtriple=x86_64 -function-sections %s -o - | FileCheck --check-prefixes=CHECK,FSECT,64 %s
+; RUN: llc -mtriple=i386 %s -o - | FileCheck --check-prefixes=CHECK,32 %s
+; RUN: llc -mtriple=x86_64 %s -o - | FileCheck --check-prefixes=CHECK,64 %s
+; RUN: llc -mtriple=x86_64 -function-sections %s -o - | FileCheck --check-prefixes=CHECK,64 %s
 
 define void @f0() "patchable-function-entry"="0" {
 ; CHECK-LABEL: f0:
@@ -16,7 +16,7 @@ define void @f1() "patchable-function-entry"="1" {
 ; CHECK-NEXT: .Lfunc_begin1:
 ; CHECK:       nop
 ; CHECK-NEXT:  ret
-; CHECK:       .section __patchable_function_entries,"awo", at progbits,f1,unique,0
+; CHECK:       .section __patchable_function_entries,"awo", at progbits,f1{{$}}
 ; 32:          .p2align 2
 ; 32-NEXT:     .long .Lfunc_begin1
 ; 64:          .p2align 3
@@ -34,8 +34,7 @@ define void @f2() "patchable-function-entry"="2" {
 ; 32-COUNT-2:  nop
 ; 64:          xchgw %ax, %ax
 ; CHECK-NEXT:  ret
-; NOFSECT:     .section __patchable_function_entries,"awo", at progbits,f2,unique,0
-; FSECT:       .section __patchable_function_entries,"awo", at progbits,f2,unique,1
+; CHECK:       .section __patchable_function_entries,"awo", at progbits,f2{{$}}
 ; 32:          .p2align 2
 ; 32-NEXT:     .long .Lfunc_begin2
 ; 64:          .p2align 3
@@ -50,8 +49,7 @@ define void @f3() "patchable-function-entry"="3" comdat {
 ; 32-COUNT-3:  nop
 ; 64:          nopl (%rax)
 ; CHECK:       ret
-; NOFSECT:     .section __patchable_function_entries,"aGwo", at progbits,f3,comdat,f3,unique,1
-; FSECT:       .section __patchable_function_entries,"aGwo", at progbits,f3,comdat,f3,unique,2
+; CHECK:       .section __patchable_function_entries,"aGwo", at progbits,f3,comdat,f3{{$}}
 ; 32:          .p2align 2
 ; 32-NEXT:     .long .Lfunc_begin3
 ; 64:          .p2align 3
@@ -66,8 +64,7 @@ define void @f5() "patchable-function-entry"="5" comdat {
 ; 32-COUNT-5:  nop
 ; 64:          nopl 8(%rax,%rax)
 ; CHECK-NEXT:  ret
-; NOFSECT      .section __patchable_function_entries,"aGwo", at progbits,f5,comdat,f5,unique,2
-; FSECT:       .section __patchable_function_entries,"aGwo", at progbits,f5,comdat,f5,unique,3
+; CHECK:       .section __patchable_function_entries,"aGwo", at progbits,f5,comdat,f5{{$}}
 ; 32:          .p2align 2
 ; 32-NEXT:     .long .Lfunc_begin4
 ; 64:          .p2align 3
@@ -91,8 +88,7 @@ define void @f3_2() "patchable-function-entry"="1" "patchable-function-prefix"="
 ;; .size does not include the prefix.
 ; CHECK:      .Lfunc_end5:
 ; CHECK-NEXT: .size f3_2, .Lfunc_end5-f3_2
-; NOFSECT:    .section __patchable_function_entries,"awo", at progbits,f3_2,unique,0
-; FSECT:      .section __patchable_function_entries,"awo", at progbits,f3_2,unique,4
+; CHECK:      .section __patchable_function_entries,"awo", at progbits,f3_2{{$}}
 ; 32:         .p2align 2
 ; 32-NEXT:    .long .Ltmp0
 ; 64:         .p2align 3


        


More information about the llvm-commits mailing list