-
-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Promote weak undefs to dynamic symbols if building DSO
475a250 changed mold's behavior on weak undefined symbols, so that if they are not resolved within the current ELF module, they are resolved to address zero. Previously, they would be promoted to dynamic symbols to give then another chance to be resolved at runtime. That change caused a regression in Firefox. Firefox uses weak undef symbols as a mean to export symbols from libxul.so. Quote from Firefox's mfbt/Types.h: > On linux mozglue is linked in the program and we link libxul.so with > -z,defs. Normally that causes the linker to reject undefined references in > libxul.so, but as a loophole it allows undefined references to weak > symbols. We add the weak attribute to the import version of the MFBT API > macros to exploit this. So, they use this as a "loophole". This change partially revert 475a250. Now, remaining weak undefs are resolved to address zero only when we are creating an executable. Fixes #114
- Loading branch information
Showing
4 changed files
with
59 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
set -e | ||
cd $(dirname $0) | ||
mold=`pwd`/../mold | ||
echo -n "Testing $(basename -s .sh $0) ... " | ||
t=$(pwd)/tmp/$(basename -s .sh $0) | ||
mkdir -p $t | ||
|
||
cat <<EOF | cc -fPIC -c -o $t/a.o -xc - | ||
#include <stdio.h> | ||
__attribute__((weak)) int foo(); | ||
int main() { | ||
printf("%d\n", foo ? foo() : 3); | ||
} | ||
EOF | ||
|
||
clang -fuse-ld=$mold -o $t/b.so $t/a.o -shared | ||
clang -fuse-ld=$mold -o $t/c.so $t/a.o -shared -Wl,-z,defs | ||
|
||
readelf --dyn-syms $t/b.so | grep -q 'WEAK DEFAULT UND foo' | ||
readelf --dyn-syms $t/c.so | grep -q 'WEAK DEFAULT UND foo' | ||
|
||
echo OK |
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,23 @@ | ||
#!/bin/bash | ||
set -e | ||
cd $(dirname $0) | ||
mold=`pwd`/../mold | ||
echo -n "Testing $(basename -s .sh $0) ... " | ||
t=$(pwd)/tmp/$(basename -s .sh $0) | ||
mkdir -p $t | ||
|
||
cat <<EOF | cc -fPIC -c -o $t/a.o -xc - | ||
#include <stdio.h> | ||
__attribute__((weak)) int foo(); | ||
int main() { | ||
printf("%d\n", foo ? foo() : 3); | ||
} | ||
EOF | ||
|
||
clang -fuse-ld=$mold -o $t/exe $t/a.o | ||
! readelf --dyn-syms $t/exe | grep -q 'WEAK DEFAULT UND foo' || false | ||
$t/exe | grep -q '^3$' | ||
|
||
echo OK |
This file was deleted.
Oops, something went wrong.