-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ELF] Support --{,no-}allow-shlib-undefined
Summary: In ld.bfd/gold, --no-allow-shlib-undefined is the default when linking an executable. This patch implements a check to error on undefined symbols in a shared object, if all of its DT_NEEDED entries are seen. Our approach resembles the one used in gold, achieves a good balance to be useful but not too smart (ld.bfd traces all DSOs and emulates the behavior of a dynamic linker to catch more cases). The error is issued based on the symbol table, different from undefined reference errors issued for relocations. It is most effective when there are DSOs that were not linked with -z defs (e.g. when static sanitizers runtime is used). gold has a comment that some system libraries on GNU/Linux may have spurious undefined references and thus system libraries should be excluded (https://sourceware.org/bugzilla/show_bug.cgi?id=6811). The story may have changed now but we make --allow-shlib-undefined the default for now. Its interaction with -shared can be discussed in the future. Reviewers: ruiu, grimar, pcc, espindola Reviewed By: ruiu Subscribers: joerg, emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D57385 llvm-svn: 352826
- Loading branch information
Showing
9 changed files
with
62 additions
and
26 deletions.
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
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
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
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
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 |
---|---|---|
@@ -1,26 +1,28 @@ | ||
# REQUIRES: x86 | ||
# --allow-shlib-undefined and --no-allow-shlib-undefined are fully | ||
# ignored in linker implementation. | ||
# --allow-shlib-undefined is set by default | ||
|
||
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o | ||
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ | ||
# RUN: %p/Inputs/allow-shlib-undefined.s -o %t | ||
# RUN: ld.lld -shared %t -o %t.so | ||
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 | ||
# RUN: %p/Inputs/allow-shlib-undefined.s -o %t1.o | ||
# RUN: ld.lld -shared %t1.o -o %t.so | ||
|
||
# RUN: ld.lld %t.o %t.so -o /dev/null | ||
# RUN: ld.lld --allow-shlib-undefined %t.o %t.so -o /dev/null | ||
# RUN: not ld.lld --no-allow-shlib-undefined %t.o %t.so -o /dev/null 2>&1 | FileCheck %s | ||
|
||
# Executable: should link with DSO containing undefined symbols in any case. | ||
# RUN: ld.lld %t1 %t.so -o %t2 | ||
# RUN: ld.lld --no-allow-shlib-undefined %t1 %t.so -o %t2 | ||
# RUN: ld.lld --allow-shlib-undefined %t1 %t.so -o %t2 | ||
# RUN: echo | llvm-mc -filetype=obj -triple=x86_64-unknown-linux -o %tempty.o | ||
# RUN: ld.lld -shared %tempty.o -o %tempty.so | ||
# RUN: ld.lld -shared %t1.o %tempty.so -o %t2.so | ||
# RUN: ld.lld --no-allow-shlib-undefined %t.o %t2.so -o /dev/null | ||
|
||
# DSO with undefines: | ||
# should link with or without any of these options. | ||
# RUN: ld.lld -shared %t -o %t.so | ||
# RUN: ld.lld -shared --allow-shlib-undefined %t -o %t.so | ||
# RUN: ld.lld -shared --no-allow-shlib-undefined %t -o %t.so | ||
|
||
# Executable still should not link when have undefines inside. | ||
# RUN: not ld.lld %t -o %t.so | ||
# RUN: ld.lld -shared %t1.o -o /dev/null | ||
# RUN: ld.lld -shared --allow-shlib-undefined %t1.o -o /dev/null | ||
# RUN: ld.lld -shared --no-allow-shlib-undefined %t1.o -o /dev/null | ||
|
||
.globl _start | ||
_start: | ||
callq _shared@PLT | ||
|
||
# CHECK: undefined reference to _unresolved |