[llvm] 791411a - [XCOFF] change the decoding of External symbol's function auxiliary entry in XCOFF32 for llvm-readobj

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 3 07:37:09 PDT 2022


Author: zhijian
Date: 2022-11-03T10:36:44-04:00
New Revision: 791411a037b10d82a8c94e7aace277f644ef9360

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

LOG: [XCOFF] change the decoding of External symbol's function auxiliary entry in XCOFF32 for llvm-readobj

Summary:

llvm-readobj decide whether to decode the external symbol's function auxiliary entry based on whether symbol is function or not currently. But the XCOFFSymbolRef::isFunction() do not work properly when -ffunction-sections is enabled. we will not decode the function auxiliary entry based on the XCOFFSymbolRef::isFunction()
we will decode the function auxiliary entry based on following:
According to the https://www.ibm.com/docs/en/aix/7.2?topic=formats-xcoff-object-file-format#XCOFF__c0f91ad419jbau

In XCOFF32, there are only "one csect Auxiliary Entry" and "a function auxiliary symbol table entry" for the C_EXT, C_WEAKEXT, and C_HIDEXT Symbols. and By convention, the csect auxiliary entry in an XCOFF32 file must be the last auxiliary entry for any external symbol that has more than one auxiliary entry( that means for the C_EXT, C_WEAKEXT, and C_HIDEXT Symbols. if there more than one auxiliary Entries. we look the last one as csect auxiliary entry. and others auxiliary entries as function entries).

Reviewers: Hubert Tong, James Henderson
Differential Revision: https://reviews.llvm.org/D136950

Added: 
    

Modified: 
    llvm/test/tools/llvm-readobj/XCOFF/symbols-invalid.test
    llvm/test/tools/llvm-readobj/XCOFF/symbols.test
    llvm/tools/llvm-readobj/XCOFFDumper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-readobj/XCOFF/symbols-invalid.test b/llvm/test/tools/llvm-readobj/XCOFF/symbols-invalid.test
index e1b1aac29b4ed..3db8803149242 100644
--- a/llvm/test/tools/llvm-readobj/XCOFF/symbols-invalid.test
+++ b/llvm/test/tools/llvm-readobj/XCOFF/symbols-invalid.test
@@ -1,10 +1,5 @@
 ## Test that we report warnings or dump raw data when symbols are invalid.
 
-# RUN: yaml2obj %s --docnum=1 -o %t1
-# RUN: llvm-readobj --syms %t1 2>&1 | FileCheck %s -DFILE=%t1 --check-prefix=CASE1
-
-# CASE1: warning: '[[FILE]]': the non-function C_EXT symbol at index 1 should have only 1 auxiliary entry, i.e. the CSECT auxiliary entry
-
 --- !XCOFF
 FileHeader:
   MagicNumber: 0x1DF
@@ -14,55 +9,45 @@ Symbols:
     StorageClass:       [[STORAGECLASS='C_EXT']]
     NumberOfAuxEntries: 2
 
-# RUN: yaml2obj %s --docnum=1 -DSTORAGECLASS='C_WEAKEXT' -o %t2
+# RUN: yaml2obj %s --docnum=1 -DSTORAGECLASS='C_STAT' -o %t1
+# RUN: llvm-readobj --syms %t1 2>&1 | FileCheck %s -DFILE=%t1 --check-prefix=CASE1
+
+# CASE1: warning: '[[FILE]]': the C_STAT symbol at index 1 should not have more than 1 auxiliary entry
+
+# RUN: yaml2obj %s --docnum=1 -DSTORAGECLASS='C_DWARF' -o %t2
 # RUN: llvm-readobj --syms %t2 2>&1 | FileCheck %s -DFILE=%t2 --check-prefix=CASE2
 
-# CASE2: warning: '[[FILE]]': the non-function C_WEAKEXT symbol at index 1 should have only 1 auxiliary entry, i.e. the CSECT auxiliary entry
+# CASE2: warning: '[[FILE]]': the C_DWARF symbol at index 1 should not have more than 1 auxiliary entry
 
-# RUN: yaml2obj %s --docnum=1 -DSTORAGECLASS='C_HIDEXT' -o %t3
+# RUN: yaml2obj %s --docnum=1 -DSTORAGECLASS='C_BLOCK' -o %t3
 # RUN: llvm-readobj --syms %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=CASE3
 
-# CASE3: warning: '[[FILE]]': the non-function C_HIDEXT symbol at index 1 should have only 1 auxiliary entry, i.e. the CSECT auxiliary entry
+# CASE3: warning: '[[FILE]]': the C_BLOCK symbol at index 1 should not have more than 1 auxiliary entry
 
-# RUN: yaml2obj %s --docnum=1 -DSTORAGECLASS='C_STAT' -o %t4
+# RUN: yaml2obj %s --docnum=1 -DSTORAGECLASS='C_FCN' -o %t4
 # RUN: llvm-readobj --syms %t4 2>&1 | FileCheck %s -DFILE=%t4 --check-prefix=CASE4
 
-# CASE4: warning: '[[FILE]]': the C_STAT symbol at index 1 should not have more than 1 auxiliary entry
-
-# RUN: yaml2obj %s --docnum=1 -DSTORAGECLASS='C_DWARF' -o %t5
-# RUN: llvm-readobj --syms %t5 2>&1 | FileCheck %s -DFILE=%t5 --check-prefix=CASE5
-
-# CASE5: warning: '[[FILE]]': the C_DWARF symbol at index 1 should not have more than 1 auxiliary entry
-
-# RUN: yaml2obj %s --docnum=1 -DSTORAGECLASS='C_BLOCK' -o %t6
-# RUN: llvm-readobj --syms %t6 2>&1 | FileCheck %s -DFILE=%t6 --check-prefix=CASE6
-
-# CASE6: warning: '[[FILE]]': the C_BLOCK symbol at index 1 should not have more than 1 auxiliary entry
-
-# RUN: yaml2obj %s --docnum=1 -DSTORAGECLASS='C_FCN' -o %t7
-# RUN: llvm-readobj --syms %t7 2>&1 | FileCheck %s -DFILE=%t7 --check-prefix=CASE7
-
-# CASE7: warning: '[[FILE]]': the C_FCN symbol at index 1 should not have more than 1 auxiliary entry
+# CASE4: warning: '[[FILE]]': the C_FCN symbol at index 1 should not have more than 1 auxiliary entry
 
 ## This case tests the raw data output ability when a file auxiliary entry does
 ## not have the matching auxiliary type.
-# RUN: yaml2obj %s --docnum=2 -o %t8
-# RUN: llvm-readobj --syms %t8 | FileCheck %s --strict-whitespace --match-full-lines --check-prefix=CASE8
-
-#      CASE8:Symbols [
-# CASE8-NEXT:  Symbol {
-# CASE8-NEXT:    Index: 0
-# CASE8-NEXT:    Name: .fun
-# CASE8-NEXT:    Value (SymbolTableIndex): 0x0
-# CASE8-NEXT:    Section: N_UNDEF
-# CASE8-NEXT:    Source Language ID: TB_C (0x0)
-# CASE8-NEXT:    CPU Version ID: 0x0
-# CASE8-NEXT:    StorageClass: C_FILE (0x67)
-# CASE8-NEXT:    NumberOfAuxEntries: 1
-# CASE8-NEXT:    !Unexpected raw auxiliary entry data:
-# CASE8-NEXT:    00000000 00000001 00020300 00000000 00fb
-# CASE8-NEXT:  }
-# CASE8-NEXT:]
+# RUN: yaml2obj %s --docnum=2 -o %t5
+# RUN: llvm-readobj --syms %t5 | FileCheck %s --strict-whitespace --match-full-lines --check-prefix=CASE5
+
+#      CASE5:Symbols [
+# CASE5-NEXT:  Symbol {
+# CASE5-NEXT:    Index: 0
+# CASE5-NEXT:    Name: .fun
+# CASE5-NEXT:    Value (SymbolTableIndex): 0x0
+# CASE5-NEXT:    Section: N_UNDEF
+# CASE5-NEXT:    Source Language ID: TB_C (0x0)
+# CASE5-NEXT:    CPU Version ID: 0x0
+# CASE5-NEXT:    StorageClass: C_FILE (0x67)
+# CASE5-NEXT:    NumberOfAuxEntries: 1
+# CASE5-NEXT:    !Unexpected raw auxiliary entry data:
+# CASE5-NEXT:    00000000 00000001 00020300 00000000 00fb
+# CASE5-NEXT:  }
+# CASE5-NEXT:]
 
 --- !XCOFF
 FileHeader:

diff  --git a/llvm/test/tools/llvm-readobj/XCOFF/symbols.test b/llvm/test/tools/llvm-readobj/XCOFF/symbols.test
index f72144c6f1a06..72ec8967cc957 100644
--- a/llvm/test/tools/llvm-readobj/XCOFF/symbols.test
+++ b/llvm/test/tools/llvm-readobj/XCOFF/symbols.test
@@ -134,6 +134,33 @@ Symbols:
         LineNumHi: 2
         LineNumLo: 3
 
+##The C_WEAKEXT symbol with two Function auxiliary entries and a CSECT auxiliary entry.
+  - Name:               .fun7
+    Value:              0x0
+    Section:            .text
+    Type:               0x00
+    StorageClass:       C_WEAKEXT
+    NumberOfAuxEntries: 3
+    AuxEntries:
+      - Type:                 AUX_FCN
+        OffsetToExceptionTbl: 2
+        SizeOfFunction:       3
+        SymIdxOfNextBeyond:   4
+        PtrToLineNum:         5
+      - Type:                 AUX_FCN
+        OffsetToExceptionTbl: 8
+        SizeOfFunction:       5
+        SymIdxOfNextBeyond:   8
+        PtrToLineNum:         5
+      - Type:                   AUX_CSECT
+        ParameterHashIndex:     11
+        TypeChkSectNum:         22
+        SymbolAlignmentAndType: 33
+        StorageMappingClass:    XMC_PR
+        SectionOrLength:        256
+        StabInfoIndex:          44
+        StabSectNum:            55
+
 # SYMBOL32:      Symbols [
 # SYMBOL32-NEXT:   Symbol {
 # SYMBOL32-NEXT:     Index: 0
@@ -304,4 +331,38 @@ Symbols:
 # SYMBOL32-NEXT:       LineNumber (Low 2 Bytes): 0x3
 # SYMBOL32-NEXT:     }
 # SYMBOL32-NEXT:   }
+# SYMBOL32-NEXT:   Symbol {
+# SYMBOL32-NEXT:     Index: 21
+# SYMBOL32-NEXT:     Name: .fun7
+# SYMBOL32-NEXT:     Value (RelocatableAddress): 0x0
+# SYMBOL32-NEXT:     Section: .text
+# SYMBOL32-NEXT:     Type: 0x0
+# SYMBOL32-NEXT:     StorageClass: C_WEAKEXT (0x6F)
+# SYMBOL32-NEXT:     NumberOfAuxEntries: 3
+# SYMBOL32-NEXT:     Function Auxiliary Entry {
+# SYMBOL32-NEXT:       Index: 22
+# SYMBOL32-NEXT:       OffsetToExceptionTable: 0x2
+# SYMBOL32-NEXT:       SizeOfFunction: 0x3
+# SYMBOL32-NEXT:       PointerToLineNum: 0x5
+# SYMBOL32-NEXT:       SymbolIndexOfNextBeyond: 4
+# SYMBOL32-NEXT:     }
+# SYMBOL32-NEXT:     Function Auxiliary Entry {
+# SYMBOL32-NEXT:       Index: 23
+# SYMBOL32-NEXT:       OffsetToExceptionTable: 0x8
+# SYMBOL32-NEXT:       SizeOfFunction: 0x5
+# SYMBOL32-NEXT:       PointerToLineNum: 0x5
+# SYMBOL32-NEXT:       SymbolIndexOfNextBeyond: 8
+# SYMBOL32-NEXT:     }
+# SYMBOL32-NEXT:     CSECT Auxiliary Entry {
+# SYMBOL32-NEXT:       Index: 24
+# SYMBOL32-NEXT:       SectionLen: 256
+# SYMBOL32-NEXT:       ParameterHashIndex: 0xB
+# SYMBOL32-NEXT:       TypeChkSectNum: 0x16
+# SYMBOL32-NEXT:       SymbolAlignmentLog2: 4
+# SYMBOL32-NEXT:       SymbolType: XTY_SD (0x1)
+# SYMBOL32-NEXT:       StorageMappingClass: XMC_PR (0x0)
+# SYMBOL32-NEXT:       StabInfoIndex: 0x2C
+# SYMBOL32-NEXT:       StabSectNum: 0x37
+# SYMBOL32-NEXT:     }
+# SYMBOL32-NEXT:   }
 # SYMBOL32-NEXT: ]

diff  --git a/llvm/tools/llvm-readobj/XCOFFDumper.cpp b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
index a2ca5b86f35e9..9e52f86a08fc9 100644
--- a/llvm/tools/llvm-readobj/XCOFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
@@ -616,22 +616,13 @@ void XCOFFDumper::printSymbol(const SymbolRef &S) {
   case XCOFF::C_EXT:
   case XCOFF::C_WEAKEXT:
   case XCOFF::C_HIDEXT: {
-    if (!SymbolEntRef.isFunction() && NumberOfAuxEntries > 1)
-      reportUniqueWarning("the non-function " +
-                          enumToString(static_cast<uint8_t>(SymbolClass),
-                                       makeArrayRef(SymStorageClass)) +
-                          " symbol at index " + Twine(SymbolIdx) +
-                          " should have only 1 auxiliary entry, i.e. the CSECT "
-                          "auxiliary entry");
-
     // For 32-bit objects, print the function auxiliary symbol table entry. The
     // last one must be a CSECT auxiliary entry.
     // For 64-bit objects, both a function auxiliary entry and an exception
     // auxiliary entry may appear, print them in the loop and skip printing the
     // CSECT auxiliary entry, which will be printed outside the loop.
     for (int I = 1; I <= NumberOfAuxEntries; I++) {
-      if ((I == NumberOfAuxEntries && !Obj.is64Bit()) ||
-          !SymbolEntRef.isFunction())
+      if (I == NumberOfAuxEntries && !Obj.is64Bit())
         break;
 
       uintptr_t AuxAddress = XCOFFObjectFile::getAdvancedSymbolEntryAddress(


        


More information about the llvm-commits mailing list