diff options
author | Amir Ayupov <aaupov@fb.com> | 2024-07-16 22:14:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-16 22:14:43 -0700 |
commit | 3fe50b6dde174c76b3380927d7dd43ac19527d64 (patch) | |
tree | 0f24da7289304e918164d32d6b6e1a2eed51a848 /bolt/test | |
parent | f0ac8903ea1c1d664d1fae16ed00e096c713aaee (diff) | |
download | llvm-3fe50b6dde174c76b3380927d7dd43ac19527d64.zip llvm-3fe50b6dde174c76b3380927d7dd43ac19527d64.tar.gz llvm-3fe50b6dde174c76b3380927d7dd43ac19527d64.tar.bz2 |
[BOLT] Store FileSymRefs in a multimap
With aggressive ICF, it's possible to have different local symbols
(under different FILE symbols) to be mapped to the same address.
FileSymRefs only keeps a single SymbolRef per address, which prevents
fragment matching from finding the correct symbol to perform parent
function lookup.
Work around this issue by switching FileSymRefs to a multimap. In
future, uses of FileSymRefs can be replaced with SortedSymbols which
keeps essentially the same information.
Test Plan: added ambiguous_fragment.test
Reviewers: dcci, ayermolo, maksfb, rafaelauler
Reviewed By: rafaelauler
Pull Request: https://github.com/llvm/llvm-project/pull/98992
Diffstat (limited to 'bolt/test')
-rw-r--r-- | bolt/test/X86/Inputs/ambiguous_fragment.s | 54 | ||||
-rw-r--r-- | bolt/test/X86/Inputs/ambiguous_fragment.script | 6 | ||||
-rw-r--r-- | bolt/test/X86/ambiguous_fragment.test | 33 |
3 files changed, 93 insertions, 0 deletions
diff --git a/bolt/test/X86/Inputs/ambiguous_fragment.s b/bolt/test/X86/Inputs/ambiguous_fragment.s new file mode 100644 index 0000000..05346ff --- /dev/null +++ b/bolt/test/X86/Inputs/ambiguous_fragment.s @@ -0,0 +1,54 @@ +#--- file1 +.file "file1.cpp" +.section .text.cold +.type __func.cold.0, @function +__func.cold.0: + ud2 + .size __func.cold.0, .-__func.cold.0 +.section .text +.type __func, @function +__func: + ud2 + .size __func, .-__func + +#--- file2 +.file "file2.cpp" +.section .text.cold +.type __func.cold.0, @function +__func.cold.0: + ud2 + .size __func.cold.0, .-__func.cold.0 +.section .text +.type __func, @function +__func: + ud2 + .size __func, .-__func + +#--- file3 +.file "file3.cpp" +.section .text.cold +.type __func.cold.0, @function +__func.cold.0: + ud2 + .size __func.cold.0, .-__func.cold.0 +.section .text +.type __func, @function +__func: + ud2 + .size __func, .-__func + +#--- file4 +.file "file4.cpp" +.section .text.cold +.type __func.cold.0, @function +__func.cold.0: + ud2 + .size __func.cold.0, .-__func.cold.0 +.section .text +.type __func, @function +__func: + ud2 + .size __func, .-__func + +#--- file5 +.file "bolt-pseudo.o" diff --git a/bolt/test/X86/Inputs/ambiguous_fragment.script b/bolt/test/X86/Inputs/ambiguous_fragment.script new file mode 100644 index 0000000..00129b8 --- /dev/null +++ b/bolt/test/X86/Inputs/ambiguous_fragment.script @@ -0,0 +1,6 @@ +SECTIONS { + . = 0x10000; + .text : { *(.text) } + . = 0x20000; + .text.cold : { *(.text.cold) } +} diff --git a/bolt/test/X86/ambiguous_fragment.test b/bolt/test/X86/ambiguous_fragment.test new file mode 100644 index 0000000..e7d32c0 --- /dev/null +++ b/bolt/test/X86/ambiguous_fragment.test @@ -0,0 +1,33 @@ +## This reproduces a bug with misidentification of a parent fragment. + +RUN: split-file %p/Inputs/ambiguous_fragment.s %t + +RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %t/file1 -o %t1.o +RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %t/file2 -o %t2.o +RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %t/file3 -o %t3.o +RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %t/file4 -o %t4.o +RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %t/file5 -o %t5.o + +RUN: ld.lld %t1.o %t2.o %t3.o %t4.o %t5.o -o %t.exe \ +RUN: --script %p/Inputs/ambiguous_fragment.script + +RUN: llvm-objcopy %t.exe %t.exe2 \ +RUN: --add-symbol=_Zfunc.cold.0=.text.cold:0x4,local,function \ +RUN: --add-symbol=_Zfunc=.text:0xc,function + +RUN: llvm-objdump --syms %t.exe2 | FileCheck %s --check-prefix=CHECK-SYMS + +RUN: link_fdata %s %t.exe2 %t.preagg PREAGG +RUN: perf2bolt -v=1 %t.exe2 -p %t.preagg --pa -o %t.fdata -w %t.yaml | FileCheck %s + +# PREAGG: B X:0 #__func# 1 0 + +CHECK-SYMS: 0000000000020004 {{.*}} __func.cold.0 +CHECK-SYMS: 0000000000020004 {{.*}} _Zfunc.cold.0 + +CHECK-NOT: BOLT-ERROR: parent function not found for __func.cold.0 +CHECK: BOLT-INFO: marking __func.cold.0/3(*4) as a fragment of __func/4(*3) +CHECK-NEXT: BOLT-INFO: marking __func.cold.0/1(*2) as a fragment of __func/1(*2) +CHECK-NEXT: BOLT-INFO: marking __func.cold.0/2(*2) as a fragment of __func/2(*2) +CHECK-NEXT: BOLT-INFO: marking __func.cold.0/3(*4) as a fragment of __func/3(*2) +CHECK-NEXT: BOLT-INFO: marking __func.cold.0/4(*2) as a fragment of __func/4(*3) |