diff options
author | David Faust <david.faust@oracle.com> | 2020-08-06 15:14:54 +0200 |
---|---|---|
committer | Jose E. Marchesi <jose.marchesi@oracle.com> | 2020-08-06 15:14:54 +0200 |
commit | 3ee9565c95f49b6f9e80641f6fda51adffc3af1e (patch) | |
tree | 5690b3e6eccd1fd4820d9dccba2540138143b3b4 /ld | |
parent | 1a9f72a7a8f445b8d665eb36b053a18e758e63e6 (diff) | |
download | binutils-gdb-3ee9565c95f49b6f9e80641f6fda51adffc3af1e.tar.gz |
bpf: relocation fixes for eBPF ELF backend
The eBPF ELF backend was not properly recording relocation addends
during installation, nor reading and applying them when performing
the final relocation. This lead to various issues with incorrect
relocations.
These issues are fixed with a new howto special function to install
the relocations, and updates to bpf_elf_relocate_section to read and
use the addends as recorded in the input_bfd.
bfd/ChangeLog
2020-08-05 David Faust <david.faust@oracle.com>
* elf64-bpf.c (bpf_elf_generic_reloc): New function.
(bpf_elf_howto_table): Use it here.
(bpf_elf_relocate_section): Use addends recorded in input_bfd for
instruction and data relocations.
ld/ChangeLog
2020-08-05 David Faust <david.faust@oracle.com>
* testsuite/ld-bpf/call-2.s: New file.
* testsuite/ld-bpf/call-2.d: Likewise.
* testsuite/ld-bpf/reloc-data-be.d: Likewise.
* testsuite/ld-bpf/reloc-data-le.d: Likewise.
* testsuite/ld-bpf/reloc-data.s: Likewise.
* testsuite/ld-bpf/reloc-insn-external-be.d: Likewise.
* testsuite/ld-bpf/reloc-insn-external-le.d: Likewise.
* testsuite/ld-bpf/reloc-insn-external.s: Likewise.
* testsuite/ld-bpf/reloc-insn32-be.d: Likewise.
* testsuite/ld-bpf/reloc-insn32-le.d: Likewise.
* testsuite/ld-bpf/reloc-insn32.s: Likewise.
* testsuite/ld-bpf/reloc-insn64-be.d: Likewise.
* testsuite/ld-bpf/reloc-insn64-le.d: Likewise.
* testsuite/ld-bpf/reloc-insn64.s: Likewise.
Diffstat (limited to 'ld')
-rw-r--r-- | ld/ChangeLog | 17 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/call-2.d | 20 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/call-2.s | 3 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/reloc-data-be.d | 11 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/reloc-data-le.d | 11 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/reloc-data.s | 16 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/reloc-insn-external-be.d | 16 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/reloc-insn-external-le.d | 16 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/reloc-insn-external.s | 5 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/reloc-insn32-be.d | 19 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/reloc-insn32-le.d | 19 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/reloc-insn32.s | 20 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/reloc-insn64-be.d | 12 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/reloc-insn64-le.d | 12 | ||||
-rw-r--r-- | ld/testsuite/ld-bpf/reloc-insn64.s | 9 |
15 files changed, 206 insertions, 0 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index b4134184714..d46e9769c08 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,20 @@ +2020-08-05 David Faust <david.faust@oracle.com> + + * testsuite/ld-bpf/call-2.s: New file. + * testsuite/ld-bpf/call-2.d: Likewise. + * testsuite/ld-bpf/reloc-data-be.d: Likewise. + * testsuite/ld-bpf/reloc-data-le.d: Likewise. + * testsuite/ld-bpf/reloc-data.s: Likewise. + * testsuite/ld-bpf/reloc-insn-external-be.d: Likewise. + * testsuite/ld-bpf/reloc-insn-external-le.d: Likewise. + * testsuite/ld-bpf/reloc-insn-external.s: Likewise. + * testsuite/ld-bpf/reloc-insn32-be.d: Likewise. + * testsuite/ld-bpf/reloc-insn32-le.d: Likewise. + * testsuite/ld-bpf/reloc-insn32.s: Likewise. + * testsuite/ld-bpf/reloc-insn64-be.d: Likewise. + * testsuite/ld-bpf/reloc-insn64-le.d: Likewise. + * testsuite/ld-bpf/reloc-insn64.s: Likewise. + 2020-08-06 Jozef Lawrynowicz <jozef.l@mittosystems.com> * emultempl/msp430.em (change_output_section): Update the tail diff --git a/ld/testsuite/ld-bpf/call-2.d b/ld/testsuite/ld-bpf/call-2.d new file mode 100644 index 00000000000..3d09095f6be --- /dev/null +++ b/ld/testsuite/ld-bpf/call-2.d @@ -0,0 +1,20 @@ +#as: --EL +#source: call-2.s +#source: bar.s +#objdump: -dr +#ld: -EL +#name: CALL with disp32 reloc and addend + +.*: +file format .*bpf.* + +Disassembly of section .text: + +[0-9a-f]+ <.*>: + *[0-9a-f]+: b7 01 00 00 01 00 00 00 mov %r1,1 + *[0-9a-f]+: 85 10 00 00 02 00 00 00 call 2 + *[0-9a-f]+: 95 00 00 00 00 00 00 00 exit + +[0-9a-f]+ <bar>: + *[0-9a-f]+: bf 21 00 00 00 00 00 00 mov %r1,%r2 + *[0-9a-f]+: bf 13 00 00 00 00 00 00 mov %r3,%r1 + *[0-9a-f]+: 95 00 00 00 00 00 00 00 exit diff --git a/ld/testsuite/ld-bpf/call-2.s b/ld/testsuite/ld-bpf/call-2.s new file mode 100644 index 00000000000..e2a5b90647d --- /dev/null +++ b/ld/testsuite/ld-bpf/call-2.s @@ -0,0 +1,3 @@ + mov %r1, 1 + call bar + 0x1 + exit diff --git a/ld/testsuite/ld-bpf/reloc-data-be.d b/ld/testsuite/ld-bpf/reloc-data-be.d new file mode 100644 index 00000000000..4d793e2b41a --- /dev/null +++ b/ld/testsuite/ld-bpf/reloc-data-be.d @@ -0,0 +1,11 @@ +#as: --EB +#source: reloc-data.s +#objdump: -s +#ld: -Tdata=0x20 -EB +#name: data relocs BE + +.*: file format .*-bpfbe + +Contents of section \.data: + 0020 666f6f00 62617200 00000000 00000020 .* + 0030 00000028 003034 .* diff --git a/ld/testsuite/ld-bpf/reloc-data-le.d b/ld/testsuite/ld-bpf/reloc-data-le.d new file mode 100644 index 00000000000..97cb1b36a2a --- /dev/null +++ b/ld/testsuite/ld-bpf/reloc-data-le.d @@ -0,0 +1,11 @@ +#as: --EL +#source: reloc-data.s +#objdump: -s +#ld: -Tdata=0x20 -EL +#name: data relocs LE + +.*: file format .*-bpfle + +Contents of section \.data: + 0020 666f6f00 62617200 20000000 00000000 .* + 0030 28000000 300034 .* diff --git a/ld/testsuite/ld-bpf/reloc-data.s b/ld/testsuite/ld-bpf/reloc-data.s new file mode 100644 index 00000000000..431ef5aef61 --- /dev/null +++ b/ld/testsuite/ld-bpf/reloc-data.s @@ -0,0 +1,16 @@ + .data +foo: + .string "foo" + + .global bar +bar: + .string "bar" + +d64: + .quad foo +d32: + .word d64 +d16: + .half d32 +d8: + .byte d16 diff --git a/ld/testsuite/ld-bpf/reloc-insn-external-be.d b/ld/testsuite/ld-bpf/reloc-insn-external-be.d new file mode 100644 index 00000000000..032d3649d2a --- /dev/null +++ b/ld/testsuite/ld-bpf/reloc-insn-external-be.d @@ -0,0 +1,16 @@ +#as: --EB +#source: reloc-data.s +#source: reloc-insn-external.s +#objdump: -dr +#ld: -Tdata=0x20 -EB +#name: reloc insn external BE + +.*: +file format .*bpfbe + +Disassembly of section .text: + +[0-9a-f]+ <.*>: + *[0-9a-f]+: 18 10 00 00 00 00 00 28[ ]*lddw %r1,0x28 + *[0-9a-f]+: 00 00 00 00 00 00 00 00[ ]* + *[0-9a-f]+: b7 20 00 00 00 00 00 26[ ]*mov %r2,0x26 + *[0-9a-f]+: 61 34 00 24 00 00 00 00[ ]*ldxw %r3,\[%r4\+0x24\] diff --git a/ld/testsuite/ld-bpf/reloc-insn-external-le.d b/ld/testsuite/ld-bpf/reloc-insn-external-le.d new file mode 100644 index 00000000000..d3513766ee8 --- /dev/null +++ b/ld/testsuite/ld-bpf/reloc-insn-external-le.d @@ -0,0 +1,16 @@ +#as: --EL +#source: reloc-data.s +#source: reloc-insn-external.s +#objdump: -dr +#ld: -Tdata=0x20 -EL +#name: reloc insn external LE + +.*: +file format .*bpfle + +Disassembly of section .text: + +[0-9a-f]+ <.*>: + *[0-9a-f]+: 18 01 00 00 28 00 00 00[ ]*lddw %r1,0x28 + *[0-9a-f]+: 00 00 00 00 00 00 00 00[ ]* + *[0-9a-f]+: b7 02 00 00 26 00 00 00[ ]*mov %r2,0x26 + *[0-9a-f]+: 61 43 24 00 00 00 00 00[ ]*ldxw %r3,\[%r4\+0x24\] diff --git a/ld/testsuite/ld-bpf/reloc-insn-external.s b/ld/testsuite/ld-bpf/reloc-insn-external.s new file mode 100644 index 00000000000..be12813934a --- /dev/null +++ b/ld/testsuite/ld-bpf/reloc-insn-external.s @@ -0,0 +1,5 @@ + + lddw %r1, bar + 4 + mov %r2, bar + 2 + + ldxw %r3, [%r4 + bar] diff --git a/ld/testsuite/ld-bpf/reloc-insn32-be.d b/ld/testsuite/ld-bpf/reloc-insn32-be.d new file mode 100644 index 00000000000..27d592d2439 --- /dev/null +++ b/ld/testsuite/ld-bpf/reloc-insn32-be.d @@ -0,0 +1,19 @@ +#as: --EB +#source: reloc-insn32.s +#objdump: -d +#ld: -Tdata=0xdabeef -EB +#name: reloc INSN32 BE + +.*: +file format .*bpfbe + +Disassembly of section .text: + +[0-9a-f]+ <main>: + *[0-9a-f]+: b7 10 00 00 00 da be f3[ ]*mov %r1,0xdabef3 + *[0-9a-f]+: 16 10 00 02 00 da be f3[ ]*jeq32 %r1,0xdabef3,2 + *[0-9a-f]+: 38 00 00 00 00 da be ff[ ]*ldabsdw 0xdabeff + *[0-9a-f]+: 95 00 00 00 00 00 00 00[ ]*exit + +[0-9a-f]+ <baz>: + *[0-9a-f]+: 07 10 00 00 00 da be ef[ ]*add %r1,0xdabeef + *[0-9a-f]+: 62 20 00 08 00 da be f7[ ]*stw \[%r2\+8\],0xdabef7 diff --git a/ld/testsuite/ld-bpf/reloc-insn32-le.d b/ld/testsuite/ld-bpf/reloc-insn32-le.d new file mode 100644 index 00000000000..bdbb45f28c6 --- /dev/null +++ b/ld/testsuite/ld-bpf/reloc-insn32-le.d @@ -0,0 +1,19 @@ +#as: --EL +#source: reloc-insn32.s +#objdump: -d +#ld: -Tdata=0xdabeef -EL +#name: reloc INSN32 LE + +.*: +file format .*bpfle + +Disassembly of section .text: + +[0-9a-f]+ <main>: + *[0-9a-f]+: b7 01 00 00 f3 be da 00[ ]*mov %r1,0xdabef3 + *[0-9a-f]+: 16 01 02 00 f3 be da 00[ ]*jeq32 %r1,0xdabef3,2 + *[0-9a-f]+: 38 00 00 00 ff be da 00[ ]*ldabsdw 0xdabeff + *[0-9a-f]+: 95 00 00 00 00 00 00 00[ ]*exit + +[0-9a-f]+ <baz>: + *[0-9a-f]+: 07 01 00 00 ef be da 00[ ]*add %r1,0xdabeef + *[0-9a-f]+: 62 02 08 00 f7 be da 00[ ]*stw \[%r2\+8\],0xdabef7 diff --git a/ld/testsuite/ld-bpf/reloc-insn32.s b/ld/testsuite/ld-bpf/reloc-insn32.s new file mode 100644 index 00000000000..a53a0dc43f8 --- /dev/null +++ b/ld/testsuite/ld-bpf/reloc-insn32.s @@ -0,0 +1,20 @@ + .data +foo: + .string "foo" +bar: + .string "bar" +d64: + .dword bar +d32: + .word d64 + + .text +main: + mov %r1, bar + jeq32 %r1, bar, baz + ldabsdw d32 + exit + +baz: + add %r1, foo + stw [%r2 + 8], d64 diff --git a/ld/testsuite/ld-bpf/reloc-insn64-be.d b/ld/testsuite/ld-bpf/reloc-insn64-be.d new file mode 100644 index 00000000000..ca74e33099c --- /dev/null +++ b/ld/testsuite/ld-bpf/reloc-insn64-be.d @@ -0,0 +1,12 @@ +#as: --EB +#source: reloc-insn64.s +#objdump: -s +#ld: -Tdata=0xdeadbeef1234 -EB +#name: reloc INSN64 big-endian + +.*: file format .*-bpfbe + +#... +Contents of section \.text: +[ ][0-9a-f]+ 18100000 beef1238 00000000 0000dead .* +#pass diff --git a/ld/testsuite/ld-bpf/reloc-insn64-le.d b/ld/testsuite/ld-bpf/reloc-insn64-le.d new file mode 100644 index 00000000000..63dcce3bd17 --- /dev/null +++ b/ld/testsuite/ld-bpf/reloc-insn64-le.d @@ -0,0 +1,12 @@ +#as: --EL +#source: reloc-insn64.s +#objdump: -s +#ld: -Tdata=0xdeadbeef1234 -EL +#name: reloc INSN64 little-endian + +.*: file format .*-bpfle + +#... +Contents of section \.text: +[ ][0-9a-f]+ 18010000 3812efbe 00000000 adde0000 .* +#pass diff --git a/ld/testsuite/ld-bpf/reloc-insn64.s b/ld/testsuite/ld-bpf/reloc-insn64.s new file mode 100644 index 00000000000..8cb1d9f896d --- /dev/null +++ b/ld/testsuite/ld-bpf/reloc-insn64.s @@ -0,0 +1,9 @@ + .data +x: + .string "foo" +y: + .string "bar" + + .text +main: + lddw %r1, y |