]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[BFD][AARCH64]Disallow R_AARCH64_ABS32(LP64) & R_AARCH64_ABS16 in const section of...
authorRenlin Li <renlin.li@arm.com>
Wed, 13 Dec 2017 12:11:25 +0000 (12:11 +0000)
committerRenlin Li <renlin.li@arm.com>
Wed, 13 Dec 2017 15:15:50 +0000 (15:15 +0000)
R_AARCH64_ABS64, R_AARCH64_ABS32 and R_AARCH64_ABS16 are data relocations
supported in AArch64 elf ABI.

R_AARCH64_ABS64 under LP64 is allowed in shared object and a dynamic relocation entry
will be generated. This allows the dynamic linker to do further symbol resolution.
R_AARCH64_ABS32 likewise is allowed in shared object, however under ILP32 abi.

The original behavior for R_AARCH64_ABS32 under LP64 is that, it's allowed
in shared object and silently resolved at static linking time.
No dynamic relocation entry is generate for it.

R_AARCH64_ABS16 is allowed in shared object under both L64 and ILP32.
It's resolved at static linking time as well.

Under LP64, the address should be 64-bit. R_AARCH64_ABS32 relocation indicates
an address that is only sized 32 bits which is meaningless in LP64 shared object.
It's useful to error out.

I have checked glibc dynamic linker code, R_AARCH64_ABS16 is not supported at all. So
R_AARCH64_ABS16 should be reject in shared object completely.

In this patch, R_AARCH64_ABS32 is rejected under LP64 in constant section of shared object.
R_AARCH64_ABS16 is rejected in constant section of shared object in both ABI.

This will sometimes provide useful information for buggy code.

bfd/ChangeLog
bfd/elfnn-aarch64.c
ld/ChangeLog
ld/testsuite/ld-aarch64/aarch64-elf.exp
ld/testsuite/ld-aarch64/emit-relocs-258-dyn-bad.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-relocs-258.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-relocs-259-dyn-bad.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/emit-relocs-259.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/gc-relocs-257.s

index 8b315fa99b1a09345c5d1d8e80a034439f6b700c..ff8feab996eae33feb9ffd7cee16a0713beacd8a 100644 (file)
@@ -1,3 +1,9 @@
+2017-12-13  Renlin Li  <renlin.li@arm.com>
+
+       * elfnn-aarch64.c (elfNN_aarch64_check_relocs): Disallow
+       BFD_RELOC_AARCH64_16 in shared object const section. Disallow
+       BFD_RELOC_AARCH64_32 in shared object const section under LP64.
+
 2017-12-11  Sangamesh Mallayya  <sangamesh.swamy@in.ibm.com>
 
        * bfd.c (bfd_get_sign_extend_vma): Correct typo.
index 212d335abcdbed28b6a806a9bcf47d63af6aa1ab..52da856df7bddd53649cc8d4f70abfb37e6fb841 100644 (file)
@@ -7070,6 +7070,27 @@ elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
 
       switch (bfd_r_type)
        {
+       case BFD_RELOC_AARCH64_16:
+#if ARCH_SIZE == 64
+       case BFD_RELOC_AARCH64_32:
+#endif
+         if (bfd_link_pic (info)
+             && (sec->flags & SEC_ALLOC) != 0
+             && (sec->flags & SEC_READONLY) != 0)
+           {
+             int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
+             _bfd_error_handler
+               /* xgettext:c-format */
+               (_("%B: relocation %s against `%s' can not be used when making "
+                  "a shared object"),
+                abfd, elfNN_aarch64_howto_table[howto_index].name,
+                (h) ? h->root.root.string : "a local symbol");
+             bfd_set_error (bfd_error_bad_value);
+             return FALSE;
+           }
+         else
+           break;
+
        case BFD_RELOC_AARCH64_MOVW_G0_NC:
        case BFD_RELOC_AARCH64_MOVW_G1_NC:
        case BFD_RELOC_AARCH64_MOVW_G2_NC:
index db025ee7b69df4cb5a1b58d0be7cc9422a5ffc3a..d0b80d1898d2fb54fc69488aedf0faf6c78ea6b4 100644 (file)
@@ -1,3 +1,13 @@
+2017-12-13  Renlin Li  <renlin.li@arm.com>
+
+       * testsuite/ld-aarch64/aarch64-elf.exp: Run new test cases.
+       * testsuite/ld-aarch64/emit-relocs-258-dyn-bad.d: New.
+       * testsuite/ld-aarch64/emit-relocs-258.s: New.
+       * testsuite/ld-aarch64/emit-relocs-259-dyn-bad.d: New.
+       * testsuite/ld-aarch64/emit-relocs-259.s: New.
+       * testsuite/ld-aarch64/gc-relocs-257.s: Put R_AARCH64_ABS32,
+       R_AARCH64_ABS16 data into data section.
+
 2017-12-07  Alan Modra  <amodra@gmail.com>
 
        PR 22465
index b9c9885cb42d142a42a2fa55a248adbaca357a24..fffc60e1b921bf5b880875047f691f50dc691ae2 100644 (file)
@@ -103,6 +103,8 @@ run_dump_test_lp64 "emit-relocs-257"
 run_dump_test_lp64 "emit-relocs-257-be"
 # 258 is tested in 257
 # 259 is tested in 257
+run_dump_test_lp64 "emit-relocs-258-dyn-bad"
+run_dump_test_lp64 "emit-relocs-259-dyn-bad"
 run_dump_test_lp64 "emit-relocs-260"
 run_dump_test_lp64 "emit-relocs-260-be"
 # 261 is tested by 260
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-258-dyn-bad.d b/ld/testsuite/ld-aarch64/emit-relocs-258-dyn-bad.d
new file mode 100644 (file)
index 0000000..4de6e55
--- /dev/null
@@ -0,0 +1,4 @@
+#name: LP64 R_AARCH64_ABS32 shared library test
+#source: emit-relocs-258.s
+#ld: -shared
+#error: .*: relocation R_AARCH64_ABS32 against `dummy' can not be used when making a shared object
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-258.s b/ld/testsuite/ld-aarch64/emit-relocs-258.s
new file mode 100644 (file)
index 0000000..f724776
--- /dev/null
@@ -0,0 +1,6 @@
+.text
+
+  ldr x0, .L1
+
+.L1:
+  .word dummy
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-259-dyn-bad.d b/ld/testsuite/ld-aarch64/emit-relocs-259-dyn-bad.d
new file mode 100644 (file)
index 0000000..f133e89
--- /dev/null
@@ -0,0 +1,4 @@
+#name: R_AARCH64_ABS16 shared library test
+#source: emit-relocs-259.s
+#ld: -shared
+#error: .*: relocation R_AARCH64_ABS16 against `dummy' can not be used when making a shared object
diff --git a/ld/testsuite/ld-aarch64/emit-relocs-259.s b/ld/testsuite/ld-aarch64/emit-relocs-259.s
new file mode 100644 (file)
index 0000000..7e1ba3c
--- /dev/null
@@ -0,0 +1,6 @@
+.text
+
+  ldr x0, .L1
+
+.L1:
+  .hword dummy
index dcc9db1b2d1bf79a0459104b529ebacc0413143a..f57f9c666979d05dc1c13f5759caaf6e5a88d5c0 100644 (file)
@@ -1,8 +1,10 @@
        .text
-       .word   tempy
+       and     x0, x0, x0
+       and     x0, x0, #0x1
        .xword  tempy2
+
+       .data
+       .word   tempy
        .hword  tempy3
        .hword  tempy3+8
 
-       and     x0, x0, x0
-       and     x0, x0, #0x1