diff --git a/lld/test/ELF/pre_init_fini_array.s b/lld/test/ELF/pre_init_fini_array.s --- a/lld/test/ELF/pre_init_fini_array.s +++ b/lld/test/ELF/pre_init_fini_array.s @@ -4,16 +4,16 @@ // RUN: ld.lld %t2 -o %t2.so -shared -soname=so // RUN: ld.lld %t %t2.so -o %t2 // RUN: llvm-readobj -r --symbols --sections --dynamic-table %t2 | FileCheck %s -// RUN: llvm-objdump -d %t2 | FileCheck --check-prefix=DISASM %s +// RUN: llvm-objdump -d --syms %t2 | FileCheck --check-prefix=DISASM %s .globl _start _start: - call __preinit_array_start - call __preinit_array_end - call __init_array_start - call __init_array_end - call __fini_array_start - call __fini_array_end + call *__preinit_array_start + call *__preinit_array_end + call *__init_array_start + call *__init_array_end + call *__fini_array_start + call *__fini_array_end .section .init_array,"aw",@init_array @@ -136,10 +136,18 @@ // CHECK-NEXT: Section: .preinit_array // CHECK-NEXT: } +// DISASM: SYMBOL TABLE: +// DISASM-DAG: {{0*}}[[#%x, PREINIT_ARRAY_START:]] l .preinit_array {{0+}} .hidden __preinit_array_start +// DISASM-DAG: {{0*}}[[#%x, PREINIT_ARRAY_END:]] l .preinit_array {{0+}} .hidden __preinit_array_end +// DISASM-DAG: {{0*}}[[#%x, INIT_ARRAY_START:]] l .init_array {{0+}} .hidden __init_array_start +// DISASM-DAG: {{0*}}[[#%x, INIT_ARRAY_END:]] l .init_array {{0+}} .hidden __init_array_end +// DISASM-DAG: {{0*}}[[#%x, FINI_ARRAY_START:]] l .fini_array {{0+}} .hidden __fini_array_start +// DISASM-DAG: {{0*}}[[#%x, FINI_ARRAY_END:]] l .fini_array {{0+}} .hidden __fini_array_end + // DISASM: <_start>: -// DISASM-NEXT: callq {{.*}} <__preinit_array_start> -// DISASM-NEXT: callq {{.*}} <__fini_array_start> -// DISASM-NEXT: callq {{.*}} <__init_array_start> -// DISASM-NEXT: callq {{.*}} <__preinit_array_start> -// DISASM-NEXT: callq {{.*}} <__fini_array_start> -// DISASM-NEXT: callq {{.*}} <__fini_array_end> +// DISASM-NEXT: callq *[[#%u, PREINIT_ARRAY_START]] +// DISASM-NEXT: callq *[[#%u, PREINIT_ARRAY_END]] +// DISASM-NEXT: callq *[[#%u, INIT_ARRAY_START]] +// DISASM-NEXT: callq *[[#%u, INIT_ARRAY_END]] +// DISASM-NEXT: callq *[[#%u, FINI_ARRAY_START]] +// DISASM-NEXT: callq *[[#%u, FINI_ARRAY_END]] diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1210,6 +1210,12 @@ SectionAddresses.emplace_back(Sec.getAddress(), Sec); stable_sort(SectionAddresses); + std::vector> CodeSectionAddresses; + for (std::pair SectionAddress : SectionAddresses) { + if (SectionAddress.second.isText()) + CodeSectionAddresses.emplace_back(SectionAddress); + } + // Linked executables (.exe and .dll files) typically don't include a real // symbol table but they might contain an export table. if (const auto *COFFObj = dyn_cast(Obj)) { @@ -1486,11 +1492,11 @@ auto *TargetSectionSymbols = &Symbols; if (!Obj->isRelocatableObject()) { auto It = partition_point( - SectionAddresses, + CodeSectionAddresses, [=](const std::pair &O) { return O.first <= Target; }); - if (It != SectionAddresses.begin()) { + if (It != CodeSectionAddresses.begin()) { --It; TargetSectionSymbols = &AllSymbols[It->second]; } else {