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 @@ -137,9 +137,9 @@ // CHECK-NEXT: } // 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 {{.*}} <_start+{{.*}}> +// DISASM-NEXT: callq {{.*}} <_start+{{.*}}> +// DISASM-NEXT: callq {{.*}} <_start+{{.*}}> +// DISASM-NEXT: callq {{.*}} <_start+{{.*}}> +// DISASM-NEXT: callq {{.*}} <_start+{{.*}}> +// DISASM-NEXT: callq {{.*}} <_start+{{.*}}> diff --git a/llvm/test/tools/llvm-objdump/X86/disassemble-functions.test b/llvm/test/tools/llvm-objdump/X86/disassemble-functions.test --- a/llvm/test/tools/llvm-objdump/X86/disassemble-functions.test +++ b/llvm/test/tools/llvm-objdump/X86/disassemble-functions.test @@ -3,9 +3,9 @@ # RUN: yaml2obj -o %t.out %p/Inputs/simple-executable-x86_64.yaml # RUN: llvm-objdump -d %t.out --disassemble-functions=main \ -# RUN: | FileCheck %s --check-prefix=MAIN --implicit-check-not=foo --implicit-check-not=somedata +# RUN: | FileCheck %s --check-prefix=MAIN --implicit-check-not=":" --implicit-check-not=":" # RUN: llvm-objdump -d %t.out --disassemble-functions=main,foo \ -# RUN: | FileCheck %s --check-prefixes=MAIN,FOO --implicit-check-not=somedata +# RUN: | FileCheck %s --check-prefixes=MAIN,FOO --implicit-check-not=":" # FOO: : # MAIN:
: 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 @@ -1208,6 +1208,12 @@ SectionAddresses.emplace_back(Sec.getAddress(), Sec); array_pod_sort(SectionAddresses.begin(), SectionAddresses.end()); + 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)) { @@ -1483,13 +1489,20 @@ 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]; + if (It != CodeSectionAddresses.begin()) { + uint64_t SelectedSectionAddr = It->first; + --It; + assert(It->first + It->second.getSize() - 1 < + SelectedSectionAddr && + "Found two code sections with call target in range"); + } } else { TargetSectionSymbols = &AbsoluteSymbols; }