bfd/elfnn-aarch64.c: Fix calculation of DT_RELASZ
authorWill Newton <will.newton@linaro.org>
Fri, 14 Mar 2014 11:45:32 +0000 (11:45 +0000)
committerWill Newton <will.newton@linaro.org>
Tue, 25 Mar 2014 09:01:50 +0000 (09:01 +0000)
The current code subtracts the size of the output section containing
relplt from RELASZ. In some cases this will be the same output
section as the dynamic relocs causing a value of zero to be output.
Calculating the size from input sections seems to make more sense.

bfd/ChangeLog:

2014-03-25  Will Newton  <will.newton@linaro.org>

 * elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_sections):
 Set value of DT_PLTRELSZ and DT_RELASZ based on the size
 of input sections rather than output sections.

ld/testsuite/ChangeLog:

2014-03-25  Will Newton  <will.newton@linaro.org>

 * ld-aarch64/aarch64-elf.exp: Add relasz dump test.
 * ld-aarch64/relasz.d: New file.
 * ld-aarch64/relasz.s: Likewise.

bfd/ChangeLog
bfd/elfnn-aarch64.c
ld/testsuite/ChangeLog
ld/testsuite/ld-aarch64/aarch64-elf.exp
ld/testsuite/ld-aarch64/relasz.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/relasz.s [new file with mode: 0644]

index c60d19d6e92b9ee180f57eb325627b53736b82b5..c719d24140cbcc8be42239013e18a81d16f5a982 100644 (file)
@@ -1,3 +1,9 @@
+2014-03-25  Will Newton  <will.newton@linaro.org>
+
+        * elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_sections):
+        Set value of DT_PLTRELSZ and DT_RELASZ based on the size
+        of input sections rather than output sections.
+
 2014-03-20  Will Newton  <will.newton@linaro.org>
 
        PR ld/16715
index c2adcc92b0040bc36b4c0708165891849e1eb54f..638938d880a419fd5ffa4f31275ac1c2e2196f22 100644 (file)
@@ -6993,7 +6993,7 @@ elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
              break;
 
            case DT_PLTRELSZ:
-             s = htab->root.srelplt->output_section;
+             s = htab->root.srelplt;
              dyn.d_un.d_val = s->size;
              break;
 
@@ -7007,7 +7007,7 @@ elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
                 about changing the DT_RELA entry.  */
              if (htab->root.srelplt != NULL)
                {
-                 s = htab->root.srelplt->output_section;
+                 s = htab->root.srelplt;
                  dyn.d_un.d_val -= s->size;
                }
              break;
index c83b4e15b97d71ed462929a1520e94e8cf81e6fa..d2002777c35312a52f0adafdb1e4068c949c6923 100644 (file)
@@ -1,3 +1,9 @@
+2014-03-25  Will Newton  <will.newton@linaro.org>
+
+        * ld-aarch64/aarch64-elf.exp: Add relasz dump test.
+        * ld-aarch64/relasz.d: New file.
+        * ld-aarch64/relasz.s: Likewise.
+
 2014-03-20  Richard Sandiford  <rdsandiford@googlemail.com>
 
        * ld-elf/merge.d: Remove MIPS XFAIL.
index 32cf73a7e76b69aedfe85e7d12a3e1b55b266a76..845ea202b4eb495bcd7f3727482aed9fe7264d51 100644 (file)
@@ -157,3 +157,5 @@ run_dump_test "ifunc-19b"
 run_dump_test "ifunc-20"
 run_dump_test "ifunc-21"
 run_dump_test "ifunc-22"
+
+run_dump_test "relasz"
diff --git a/ld/testsuite/ld-aarch64/relasz.d b/ld/testsuite/ld-aarch64/relasz.d
new file mode 100644 (file)
index 0000000..5cc5595
--- /dev/null
@@ -0,0 +1,18 @@
+#source: relasz.s
+#ld: -shared -Taarch64.ld
+#readelf: -d
+# Check that the RELASZ section has the correct size even if we are
+# using a non-default linker script that merges .rela.dyn and .rela.plt
+# in the output.
+
+Dynamic section at offset 0x[0-9a-f]+ contains 9 entries:
+  Tag        Type                         Name/Value
+ 0x0000000000000004 \(HASH\)               0x[0-9a-f]+
+ 0x0000000000000005 \(STRTAB\)             0x[0-9a-f]+
+ 0x0000000000000006 \(SYMTAB\)             0x[0-9a-f]+
+ 0x000000000000000a \(STRSZ\)              [0-9]+ \(bytes\)
+ 0x000000000000000b \(SYMENT\)             [0-9]+ \(bytes\)
+ 0x0000000000000007 \(RELA\)               0x[0-9a-f]+
+ 0x0000000000000008 \(RELASZ\)             24 \(bytes\)
+ 0x0000000000000009 \(RELAENT\)            24 \(bytes\)
+ 0x0000000000000000 \(NULL\)               0x0
diff --git a/ld/testsuite/ld-aarch64/relasz.s b/ld/testsuite/ld-aarch64/relasz.s
new file mode 100644 (file)
index 0000000..8c7f891
--- /dev/null
@@ -0,0 +1,9 @@
+       .text
+       .global func
+       .type   func, %function
+func:
+       adrp    x0, :got:foo
+       ldr     x0, [x0, #:got_lo12:foo]
+       ldr     w0, [x0]
+       ret
+       .size   func, .-func