-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BOLT] do not search for PLT entries if the relocation is against a w…
…eak reference symbol. Take a common weak reference pattern for example ``` __attribute__((weak)) void undef_weak_fun(); if (&undef_weak_fun) undef_weak_fun(); ``` In this case, an undefined weak symbol `undef_weak_fun` has an address of zero, and Bolt incorrectly changes the relocation for the corresponding symbol to symbol@PLT, leading to incorrect runtime behavior.
- Loading branch information
1 parent
1343d96
commit 2acdf00
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// This test checks whether BOLT can correctly handle relocations against weak symbols. | ||
|
||
// RUN: %clang %cflags -Wl,-z,notext -shared -Wl,-q %s -o %t.so | ||
// RUN: llvm-bolt %t.so -o %t.so.bolt | ||
// RUN: llvm-nm -n %t.so.bolt > %t.out.txt | ||
// RUN: llvm-objdump -dj .rodata %t.so.bolt >> %t.out.txt | ||
// RUN: FileCheck %s --input-file=%t.out.txt | ||
|
||
# CHECK: w func_1 | ||
# CHECK: {{0+}}[[#%x,ADDR:]] W func_2 | ||
|
||
# CHECK: {{.*}} <.rodata>: | ||
# CHECK-NEXT: {{.*}} .word 0x00000000 | ||
# CHECK-NEXT: {{.*}} .word 0x00000000 | ||
# CHECK-NEXT: {{.*}} .word 0x{{[0]+}}[[#ADDR]] | ||
# CHECK-NEXT: {{.*}} .word 0x00000000 | ||
|
||
.text | ||
.weak func_2 | ||
.weak func_1 | ||
.global wow | ||
.type wow, %function | ||
wow: | ||
bl func_1 | ||
bl func_2 | ||
ret | ||
.type func_2, %function | ||
func_2: | ||
ret | ||
.section .rodata | ||
.LC0: | ||
.xword func_1 | ||
.LC1: | ||
.xword func_2 |