Index: llvm/lib/ObjectYAML/ELFEmitter.cpp =================================================================== --- llvm/lib/ObjectYAML/ELFEmitter.cpp +++ llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -251,13 +251,12 @@ ELFYAML::Chunk::ChunkKind::RawContent, /*IsImplicit=*/true)); std::vector ImplicitSections; + if (Doc.DynamicSymbols) + ImplicitSections.insert(ImplicitSections.end(), {".dynsym", ".dynstr"}); if (Doc.Symbols) ImplicitSections.push_back(".symtab"); ImplicitSections.insert(ImplicitSections.end(), {".strtab", ".shstrtab"}); - if (Doc.DynamicSymbols) - ImplicitSections.insert(ImplicitSections.end(), {".dynsym", ".dynstr"}); - // Insert placeholders for implicit sections that are not // defined explicitly in YAML. for (StringRef SecName : ImplicitSections) { Index: llvm/test/tools/llvm-objcopy/ELF/add-symbol-no-symtab.test =================================================================== --- llvm/test/tools/llvm-objcopy/ELF/add-symbol-no-symtab.test +++ llvm/test/tools/llvm-objcopy/ELF/add-symbol-no-symtab.test @@ -86,13 +86,13 @@ # RUN: llvm-objcopy --add-symbol='abs1=1' %t3.no %t3.not.dynstr # RUN: llvm-readobj -S %t3.not.dynstr | FileCheck --check-prefix=SEC3 %s -# SEC3: Index: 1 +# SEC3: Index: 3 # SEC3-NEXT: Name: .shstrtab # SEC3-NEXT: Type: SHT_STRTAB # SEC3: Name: .symtab # SEC3-NEXT: Type: SHT_SYMTAB # SEC3-NOT: } -# SEC3: Link: 1 +# SEC3: Link: 3 --- !ELF FileHeader: Index: llvm/test/tools/llvm-readobj/ELF/dynamic-reloc-no-section-headers.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/dynamic-reloc-no-section-headers.test +++ llvm/test/tools/llvm-readobj/ELF/dynamic-reloc-no-section-headers.test @@ -47,10 +47,10 @@ Value: 0x88 - Tag: DT_STRSZ Value: 0x5 -## Offset of .dynstr is 0x19f. Offset of PT_LOAD is 0xb0. -## 0x19f - 0xb0 == 0xef +## Offset of .dynstr is 0x168. Offset of PT_LOAD is 0xb0. +## 0x168 - 0xb0 == 0xb8 - Tag: DT_STRTAB - Value: 0xef + Value: 0xb8 - Tag: DT_NULL Value: 0x0 - Name: .dynsym Index: llvm/test/tools/llvm-readobj/ELF/hidden-versym.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/hidden-versym.test +++ llvm/test/tools/llvm-readobj/ELF/hidden-versym.test @@ -2,7 +2,7 @@ # RUN: llvm-readelf -V %t | FileCheck %s --check-prefix=HIDDEN # HIDDEN: Version symbols section '.gnu.version' contains 2 entries: -# HIDDEN-NEXT: Addr: 0000000000200210 Offset: 0x000040 Link: 5 (.dynsym) +# HIDDEN-NEXT: Addr: 0000000000200210 Offset: 0x000040 Link: 3 (.dynsym) # HIDDEN-NEXT: 000: 0 (*local*) 3h(hiddensym) --- !ELF Index: llvm/test/tools/llvm-readobj/ELF/reloc-symbol-with-versioning.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/reloc-symbol-with-versioning.test +++ llvm/test/tools/llvm-readobj/ELF/reloc-symbol-with-versioning.test @@ -64,7 +64,7 @@ Type: SHT_RELA Flags: [ SHF_ALLOC ] Info: 0 - Link: 7 + Link: .dynsym AddressAlign: 0x0000000000000008 EntSize: 0x0000000000000018 Relocations: Index: llvm/test/tools/llvm-readobj/ELF/verdef-invalid.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/verdef-invalid.test +++ llvm/test/tools/llvm-readobj/ELF/verdef-invalid.test @@ -52,7 +52,7 @@ # RUN: llvm-readobj -V %t3 2>&1 | FileCheck %s --check-prefix=INVALID-DATA -DFILE=%t3 # RUN: llvm-readelf -V %t3 2>&1 | FileCheck %s --check-prefix=INVALID-DATA -DFILE=%t3 -# INVALID-DATA: warning: '[[FILE]]': cannot read content of SHT_GNU_verdef section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that is greater than the file size (0x230) +# INVALID-DATA: warning: '[[FILE]]': cannot read content of SHT_GNU_verdef section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that is greater than the file size (0x228) --- !ELF FileHeader: @@ -281,7 +281,7 @@ # INVALID-VERDEF-LLVM-NEXT: Name: foo@ # INVALID-VERDEF-GNU: Version symbols section '.gnu.version' contains 2 entries: -# INVALID-VERDEF-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 5 (.dynsym) +# INVALID-VERDEF-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 3 (.dynsym) # INVALID-VERDEF-GNU-NEXT: warning: '[[FILE]]': unable to get a version for entry 1 of SHT_GNU_versym section with index 1: invalid SHT_GNU_verdef section with index 2: version definition 1 goes past the end of the section # INVALID-VERDEF-GNU-NEXT: 000: 0 (*local*) 2 () Index: llvm/test/tools/llvm-readobj/ELF/verneed-invalid.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/verneed-invalid.test +++ llvm/test/tools/llvm-readobj/ELF/verneed-invalid.test @@ -9,11 +9,11 @@ # RUN: llvm-readobj -V %t1 | FileCheck %s --check-prefix=LLVM-VERNEED-NAME # GNU-VERNEED-NAME: Version symbols section '.gnu.version' contains 2 entries: -# GNU-VERNEED-NAME-NEXT: Addr: 0000000000200210 Offset: 0x000040 Link: 5 (.dynsym) +# GNU-VERNEED-NAME-NEXT: Addr: 0000000000200210 Offset: 0x000040 Link: 3 (.dynsym) # GNU-VERNEED-NAME-NEXT: 000: 0 (*local*) 2 () # GNU-VERNEED-NAME: Version needs section '.gnu.version_r' contains 1 entries: -# GNU-VERNEED-NAME-NEXT: Addr: 0000000000000000 Offset: 0x000044 Link: 6 (.dynstr) +# GNU-VERNEED-NAME-NEXT: Addr: 0000000000000000 Offset: 0x000044 Link: 4 (.dynstr) # GNU-VERNEED-NAME-NEXT: 0x0000: Version: 1 File: somefile Cnt: 1 # GNU-VERNEED-NAME-NEXT: 0x0010: Name: Flags: none Version: 2 @@ -85,7 +85,7 @@ # RUN: llvm-readobj -V %t2 2>&1 | FileCheck %s -DFILE=%t2 --check-prefix=LLVM-NOLINK # GNU-NOLINK: Version symbols section '.gnu.version' contains 2 entries: -# GNU-NOLINK-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 5 (.dynsym) +# GNU-NOLINK-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 3 (.dynsym) # GNU-NOLINK-NEXT: warning: '[[FILE]]': invalid string table linked to SHT_GNU_verneed section with index 2: invalid sh_type for string table section [index 0]: expected SHT_STRTAB, but got SHT_NULL # GNU-NOLINK-NEXT: 000: 0 (*local*) 2 () # GNU-NOLINK: Version needs section '.gnu.version_r' contains 1 entries: @@ -159,7 +159,7 @@ # RUN: llvm-readobj -V %t3 2>&1 | FileCheck %s -DFILE=%t3 --check-prefix=BROKEN-AUX-LLVM # BROKEN-AUX-GNU: Version symbols section '.gnu.version' contains 1 entries: -# BROKEN-AUX-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 5 (.dynsym) +# BROKEN-AUX-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 3 (.dynsym) # BROKEN-AUX-GNU-NEXT: warning: '[[FILE]]': unable to get a version for entry 0 of SHT_GNU_versym section with index 1: invalid SHT_GNU_verneed section with index 2: found a misaligned auxiliary entry at offset 0x11 # BROKEN-AUX-GNU-NEXT: 000: 2 () @@ -377,7 +377,7 @@ # RUN: llvm-readobj --sections -V %t7 2>&1 | FileCheck %s -DFILE=%t7 --check-prefix=INVALID-DATA # RUN: llvm-readelf --sections -V %t7 2>&1 | FileCheck %s -DFILE=%t7 --check-prefix=INVALID-DATA -# INVALID-DATA: warning: '[[FILE]]': cannot read content of SHT_GNU_verneed section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that is greater than the file size (0x230) +# INVALID-DATA: warning: '[[FILE]]': cannot read content of SHT_GNU_verneed section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that is greater than the file size (0x228) --- !ELF FileHeader: @@ -559,7 +559,7 @@ # RUN: llvm-readobj -V %t13 2>&1 | FileCheck %s -DFILE=%t13 --check-prefix=LLVM-CUSTOM-DYNSTR # GNU-CUSTOM-DYNSTR: Version symbols section '.gnu.version' contains 2 entries: -# GNU-CUSTOM-DYNSTR-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 6 (.dynsym) +# GNU-CUSTOM-DYNSTR-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 4 (.dynsym) # GNU-CUSTOM-DYNSTR-NEXT: 000: 0 (*local*) 2 (bcdefghij) # GNU-CUSTOM-DYNSTR: Version needs section '.gnu.version_r' contains 1 entries: # GNU-CUSTOM-DYNSTR-NEXT: Addr: 0000000000000000 Offset: 0x000044 Link: 3 (.custom.dynstr) Index: llvm/test/tools/llvm-readobj/ELF/versioninfo.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/versioninfo.test +++ llvm/test/tools/llvm-readobj/ELF/versioninfo.test @@ -270,12 +270,12 @@ # LLVM-NEXT: ] # GNU: Version symbols section '.gnu.version' contains 6 entries: -# GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 6 (.dynsym) +# GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 4 (.dynsym) # GNU-NEXT: 000: 0 (*local*) 2 (VERSION1) 3 (VERSION2) 4 (v1) # GNU-NEXT: 004: 5 (v2) 6 (v3) # GNU-EMPTY: # GNU-NEXT: Version definition section '.gnu.version_d' contains 6 entries: -# GNU-NEXT: Addr: 0000000000000000 Offset: 0x00004c Link: 7 (.dynstr) +# GNU-NEXT: Addr: 0000000000000000 Offset: 0x00004c Link: 5 (.dynstr) # GNU-NEXT: 0x0000: Rev: 1 Flags: none Index: 0 Cnt: 1 Name: VERSION1 # GNU-NEXT: 0x001c: Rev: 1 Flags: BASE Index: 0 Cnt: 1 Name: VERSION1 # GNU-NEXT: 0x0038: Rev: 1 Flags: WEAK Index: 0 Cnt: 1 Name: VERSION1 @@ -286,7 +286,7 @@ # GNU-NEXT: 0x00b0: Parent 2: VERSION3 # GNU-EMPTY: # GNU-NEXT: Version needs section '.gnu.version_r' contains 2 entries: -# GNU-NEXT: Addr: 0000000000000000 Offset: 0x000104 Link: 7 (.dynstr) +# GNU-NEXT: Addr: 0000000000000000 Offset: 0x000104 Link: 5 (.dynstr) # GNU-NEXT: 0x0000: Version: 1 File: verneed1.so.0 Cnt: 5 # GNU-NEXT: 0x0010: Name: v1 Flags: BASE Version: 0 # GNU-NEXT: 0x0020: Name: v1 Flags: WEAK Version: 0 Index: llvm/test/tools/llvm-readobj/ELF/versym-invalid.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/versym-invalid.test +++ llvm/test/tools/llvm-readobj/ELF/versym-invalid.test @@ -63,12 +63,12 @@ # RUN: llvm-readobj -V %t3 2>&1 | FileCheck -DFILE=%t3 %s --check-prefix=INVALID-STRING-TABLE-LLVM # INVALID-STRING-TABLE-GNU: Version symbols section '.gnu.version' contains 1 entries: -# INVALID-STRING-TABLE-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 5 (.dynsym) -# INVALID-STRING-TABLE-GNU-NEXT: warning: '[[FILE]]': can't get a string table for the symbol table linked to SHT_GNU_versym section with index 1: invalid string table linked to SHT_DYNSYM section with index 5: invalid sh_type for string table section [index 2]: expected SHT_STRTAB, but got SHT_NULL +# INVALID-STRING-TABLE-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 3 (.dynsym) +# INVALID-STRING-TABLE-GNU-NEXT: warning: '[[FILE]]': can't get a string table for the symbol table linked to SHT_GNU_versym section with index 1: invalid string table linked to SHT_DYNSYM section with index 3: invalid sh_type for string table section [index 2]: expected SHT_STRTAB, but got SHT_NULL # INVALID-STRING-TABLE-GNU-NEXT: 000: 0 (*local*) # INVALID-STRING-TABLE-LLVM: VersionSymbols [ -# INVALID-STRING-TABLE-LLVM-NEXT: warning: '[[FILE]]': can't get a string table for the symbol table linked to SHT_GNU_versym section with index 1: invalid string table linked to SHT_DYNSYM section with index 5: invalid sh_type for string table section [index 2]: expected SHT_STRTAB, but got SHT_NULL +# INVALID-STRING-TABLE-LLVM-NEXT: warning: '[[FILE]]': can't get a string table for the symbol table linked to SHT_GNU_versym section with index 1: invalid string table linked to SHT_DYNSYM section with index 3: invalid sh_type for string table section [index 2]: expected SHT_STRTAB, but got SHT_NULL # INVALID-STRING-TABLE-LLVM-NEXT: ] --- !ELF @@ -145,12 +145,12 @@ # RUN: llvm-readobj -V %t6 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=SYMBOLS-NUM-MISMATCH-LLVM # SYMBOLS-NUM-MISMATCH-GNU: Version symbols section '.gnu.version' contains 2 entries: -# SYMBOLS-NUM-MISMATCH-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 4 (.dynsym) -# SYMBOLS-NUM-MISMATCH-GNU-NEXT: warning: '[[FILE]]': SHT_GNU_versym section with index 1: the number of entries (2) does not match the number of symbols (3) in the symbol table with index 4 +# SYMBOLS-NUM-MISMATCH-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.dynsym) +# SYMBOLS-NUM-MISMATCH-GNU-NEXT: warning: '[[FILE]]': SHT_GNU_versym section with index 1: the number of entries (2) does not match the number of symbols (3) in the symbol table with index 2 # SYMBOLS-NUM-MISMATCH-GNU-NEXT: 000: 0 (*local*) 1 (*global*) # SYMBOLS-NUM-MISMATCH-LLVM: VersionSymbols [ -# SYMBOLS-NUM-MISMATCH-LLVM-NEXT: warning: '[[FILE]]': SHT_GNU_versym section with index 1: the number of entries (2) does not match the number of symbols (3) in the symbol table with index 4 +# SYMBOLS-NUM-MISMATCH-LLVM-NEXT: warning: '[[FILE]]': SHT_GNU_versym section with index 1: the number of entries (2) does not match the number of symbols (3) in the symbol table with index 2 # SYMBOLS-NUM-MISMATCH-LLVM-NEXT: ] --- !ELF Index: llvm/test/tools/yaml2obj/ELF/dynamic-symbols.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/dynamic-symbols.yaml +++ llvm/test/tools/yaml2obj/ELF/dynamic-symbols.yaml @@ -52,7 +52,7 @@ # NUM: Name: bar # NUM: Section: -# NUM-SAME: .strtab (0x2) +# NUM-SAME: .dynsym (0x2) # NUM: Name: zed # NUM: warning: '[[FILE]]': invalid section index: 255 Index: llvm/test/tools/yaml2obj/ELF/gnu-hash-section.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/gnu-hash-section.yaml +++ llvm/test/tools/yaml2obj/ELF/gnu-hash-section.yaml @@ -13,13 +13,15 @@ # CONTENT-NEXT: Address: 0x0 # CONTENT-NEXT: Offset: 0x40 # CONTENT-NEXT: Size: 3 -# CONTENT-NEXT: Link: 4 +# CONTENT-NEXT: Link: 2 # CONTENT-NEXT: Info: 0 # CONTENT-NEXT: AddressAlignment: 0 # CONTENT-NEXT: EntrySize: 0 # CONTENT-NEXT: SectionData ( # CONTENT-NEXT: 0000: 001122 | # CONTENT-NEXT: ) +# CONTENT: Index: 2 +# CONTENT-NEXT: Name: .dynsym (9) --- !ELF FileHeader: Index: llvm/test/tools/yaml2obj/ELF/implicit-sections-info.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/implicit-sections-info.yaml +++ llvm/test/tools/yaml2obj/ELF/implicit-sections-info.yaml @@ -11,18 +11,18 @@ # RUN: yaml2obj --docnum=1 %s -o %t # RUN: llvm-readobj --sections %t | FileCheck %s --check-prefix=CASE1 -# CASE1: Name: .symtab -# CASE1: Info: -# CASE1-SAME: 2 -# CASE1: Name: .strtab -# CASE1: Info: -# CASE1-SAME: 0 -# CASE1: Name: .dynsym -# CASE1: Info: -# CASE1-SAME: 1 -# CASE1: Name: .dynstr -# CASE1: Info: -# CASE1-SAME: 0 +# CASE1: Name: .symtab +# CASE1-NOT: Info: +# CASE1: Info: 2{{$}} +# CASE1: Name: .strtab +# CASE1-NOT: Info: +# CASE1: Info: 0{{$}} +# CASE1: Name: .dynsym +# CASE1-NOT: Info: +# CASE1: Info: 1{{$}} +# CASE1: Name: .dynstr +# CASE1-NOT: Info: +# CASE1: Info: 0{{$}} --- !ELF FileHeader: @@ -51,7 +51,20 @@ ## behavior is the same as when we define them, but do not set the Info. # RUN: yaml2obj --docnum=2 %s -o %t -# RUN: llvm-readobj --sections %t | FileCheck %s --check-prefix=CASE1 +# RUN: llvm-readobj --sections %t | FileCheck %s --check-prefix=CASE2 + +# CASE2: Name: .dynsym +# CASE2: Info: +# CASE2-SAME: 1 +# CASE2: Name: .dynstr +# CASE2: Info: +# CASE2-SAME: 0 +# CASE2: Name: .symtab +# CASE2: Info: +# CASE2-SAME: 2 +# CASE2: Name: .strtab +# CASE2: Info: +# CASE2-SAME: 0 --- !ELF FileHeader: @@ -70,20 +83,20 @@ ## Check we are able to set any sh_info explicitly. # RUN: yaml2obj --docnum=3 %s -o %t -# RUN: llvm-readobj --sections %t | FileCheck %s --check-prefix=CASE2 +# RUN: llvm-readobj --sections %t | FileCheck %s --check-prefix=CASE3 -# CASE2: Name: .dynstr -# CASE2: Info: -# CASE2-SAME: 10 -# CASE2: Name: .dynsym -# CASE2: Info: -# CASE2-SAME: 11 -# CASE2: Name: .strtab -# CASE2: Info: -# CASE2-SAME: 12 -# CASE2: Name: .symtab -# CASE2: Info: -# CASE2-SAME: 13 +# CASE3: Name: .dynstr +# CASE3: Info: +# CASE3-SAME: 10 +# CASE3: Name: .dynsym +# CASE3: Info: +# CASE3-SAME: 11 +# CASE3: Name: .strtab +# CASE3: Info: +# CASE3-SAME: 12 +# CASE3: Name: .symtab +# CASE3: Info: +# CASE3-SAME: 13 --- !ELF FileHeader: Index: llvm/test/tools/yaml2obj/ELF/implicit-sections-types.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/implicit-sections-types.yaml +++ llvm/test/tools/yaml2obj/ELF/implicit-sections-types.yaml @@ -7,16 +7,16 @@ # RUN: yaml2obj --docnum=1 %s -o %t1 # RUN: llvm-readobj -S %t1 | FileCheck %s --check-prefix=CASE1 +# CASE1: Name: .dynsym +# CASE1-NEXT: Type: SHT_DYNSYM +# CASE1: Name: .dynstr +# CASE1-NEXT: Type: SHT_STRTAB # CASE1: Name: .symtab # CASE1-NEXT: Type: SHT_SYMTAB # CASE1: Name: .strtab # CASE1-NEXT: Type: SHT_STRTAB # CASE1: Name: .shstrtab # CASE1-NEXT: Type: SHT_STRTAB -# CASE1: Name: .dynsym -# CASE1-NEXT: Type: SHT_DYNSYM -# CASE1: Name: .dynstr -# CASE1-NEXT: Type: SHT_STRTAB --- !ELF FileHeader: