diff options
author | midipix <writeonce@midipix.org> | 2016-05-18 05:09:56 -0400 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2016-05-18 14:49:24 -0400 |
commit | 11489e4bc6d0c6eaa68df5fefb6ebfb982f9b5c7 (patch) | |
tree | 9d08d8fdd37febc392d428cf3748ab0440bebb94 | |
parent | 2fbdf2a35af928d23045d55a3a9c5ee1152f5046 (diff) | |
download | chainport-11489e4bc6d0c6eaa68df5fefb6ebfb982f9b5c7.tar.bz2 chainport-11489e4bc6d0c6eaa68df5fefb6ebfb982f9b5c7.tar.xz |
binutils-2.24.51: updated patch.
+ PE/COFF: properly handle references to addresses of weak data symbols.
+ a special thanks to Rich Felker, primary author of musl libc, for invaluable
help and direction.
+ while commit 8dfab477 did resolve binutils bug 16858, it did not address the
issue of references to weak data symbols. Before this patch, assembly of the
the following minimal example would result in p holding offset of dummy from
the beginning of the .data section which is always wrong (weak data symbols
should be treated the same way as external symbols) and never needed, namely
since the recorded dependency on 'a' suffices for the linker even in cases
where the strong symbol 'a' is not present.
+ relevant code path:
md_apply_fix(): for PE targets, and given a relocation based on a weak
symbol that is *not* a function, store the inverse of
the symbol value, retrieved via S_GET_VALUE (fixP->fx_addsy);
bfd_install_relocation(): here we relocate based on the weak symbol's
value: relocation = symbol->value; this value is later
added to the value that was stored to memory in the
previous step: DOIT(x); the result is zero plus any
offset that is symbol-relative (array member, etc.)
== TEST CASE ==
.data
.globl top
.balign 8
top:
.quad 0x12345678
.balign 4
dummy:
.long 7
.globl p
.balign 8
p:
.quad a
.weak a
.set a,dummy
== VERIFICATION ==
a.o: file format pe-x86-64
Disassembly of section .data:
0000000000000000 <top>:
0: 78 56 js 58 <p+0x48>
2: 34 12 xor $0x12,%al
4: 00 00 add %al,(%rax)
...
0000000000000008 <.weak.a.top>:
8: 07 (bad)
9: 00 00 add %al,(%rax)
b: 00 00 add %al,(%rax)
d: 00 00 add %al,(%rax)
...
0000000000000010 <p>:
...
10: R_X86_64_64 a
signed-off by Z. Gilboa; see copying.midipix (9cd0746c) for additional information.
-rw-r--r-- | binutils-2.24.51.midipix.patch | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/binutils-2.24.51.midipix.patch b/binutils-2.24.51.midipix.patch index 8fa7400..9a11478 100644 --- a/binutils-2.24.51.midipix.patch +++ b/binutils-2.24.51.midipix.patch @@ -709,6 +709,20 @@ diff -ru a/gas/config/tc-i386.c b/gas/config/tc-i386.c /* Fix a few things - the dynamic linker expects certain values here, and we must not disappoint it. */ +@@ -9237,8 +9218,11 @@ + fixP->fx_done = 0; + /* Remember value for tc_gen_reloc. */ + fixP->fx_addnumber = value; +- /* Clear out the frag for now. */ +- value = 0; ++ /* for data symbols, cancel the effect of the relocation */ ++ if (!((S_GET_SEGMENT (fixP->fx_addsy)->flags) & SEC_CODE)) ++ value = -S_GET_VALUE (fixP->fx_addsy); ++ else ++ value = 0; + } + #endif + else if (use_rela_relocations) --- a/binutils/rename.c 2014-07-03 01:37:22.000000000 -0400 +++ b/binutils/rename.c 2015-11-25 23:13:38.086948592 -0500 |