[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:
Maksim Panchenko 2021-06-18 14:35:39 -07:00
parent ba915af1cd
commit bbbd159ccb
3 changed files with 43 additions and 0 deletions

View File

@ -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();

View 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);
}

View 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