mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-14 19:49:36 +00:00
[BOLT] Fix undefined symbol warnings/errors
Summary: When we fold a function in relocation mode, make sure to clear its state to avoid emitting relocations against undefined symbols. (cherry picked from FBD29245320)
This commit is contained in:
parent
ba915af1cd
commit
bbbd159ccb
@ -1284,6 +1284,7 @@ void BinaryContext::foldFunction(BinaryFunction &ChildBF,
|
||||
assert(&ChildBF == &FI->second && "function mismatch");
|
||||
|
||||
WriteBfsLock.lock();
|
||||
ChildBF.clearDisasmState();
|
||||
FI = BinaryFunctions.erase(FI);
|
||||
WriteBfsLock.unlock();
|
||||
|
||||
|
29
bolt/test/X86/Inputs/icf-jump-tables.c
Normal file
29
bolt/test/X86/Inputs/icf-jump-tables.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int inc(int x) {
|
||||
switch (x) {
|
||||
case 0: puts("0"); return 1;
|
||||
case 1: puts("1"); return 2;
|
||||
case 2: puts("2"); return 3;
|
||||
case 3: puts("3"); return 4;
|
||||
case 4: puts("4"); return 5;
|
||||
case 5: puts("5"); return 6;
|
||||
default: return x + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int inc_dup(int x) {
|
||||
switch (x) {
|
||||
case 0: puts("0"); return 1;
|
||||
case 1: puts("1"); return 2;
|
||||
case 2: puts("2"); return 3;
|
||||
case 3: puts("3"); return 4;
|
||||
case 4: puts("4"); return 5;
|
||||
case 5: puts("5"); return 6;
|
||||
default: return x + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
return inc(5) - 2*inc_dup(2);
|
||||
}
|
13
bolt/test/X86/icf-jump-tables.test
Normal file
13
bolt/test/X86/icf-jump-tables.test
Normal file
@ -0,0 +1,13 @@
|
||||
## Check that BOLT folds functions with jump tables and does not report
|
||||
## undefined symbols.
|
||||
|
||||
# REQUIRES: system-linux
|
||||
|
||||
# RUN: %host_cc %cflags -O1 -g %p/Inputs/icf-jump-tables.c -o %t.exe -Wl,-q
|
||||
# RUN: llvm-bolt %t.exe -icf -o %t.bolt |& FileCheck %s
|
||||
|
||||
## Check that BOLT successfully folded a function with jump table:
|
||||
# CHECK: ICF folded 1
|
||||
|
||||
## Check that no relocations against undefined symbols were emitted:
|
||||
# CHECK-NOT: Undefined temporary symbol
|
Loading…
Reference in New Issue
Block a user