From: Tamar Christina <tamar.christina@arm.com>
To: binutils@sourceware.org
Cc: nd@arm.com, Richard.Earnshaw@arm.com, nickc@redhat.com,
ramana.radhakrishnan@arm.com, suratiamol@gmail.com
Subject: [PATCH 2/2][Binutils][Arm]: Fix LSB of GOT for Thumb2 only PLT
Date: Mon, 30 Mar 2020 09:12:21 +0100 [thread overview]
Message-ID: <20200330081219.GA16551@arm.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1934 bytes --]
Hi All,
When you have a Thumb only PLT then the address in the GOT for PLT0 needs to
have the Thumb bit set since the instruction used in PLTn to get there is
`ldr.w pc` which is an inter-working instruction:
the PLT sequence in question is
00000120 <foo@plt>:
120: f240 0c98 movw ip, #152 ; 0x98
124: f2c0 0c01 movt ip, #1
128: 44fc add ip, pc
12a: f8dc f000 ldr.w pc, [ip]
12e: e7fc b.n 12a <foo@plt+0xa>
Disassembly of section .text:
00000130 <bar>:
130: b580 push {r7, lr}
132: af00 add r7, sp, #0
134: f7ff fff4 bl 120 <foo@plt>
and previously the linker would generate
Hex dump of section '.got':
...
0x000101b8 40010100 00000000 00000000 10010000 @...............
Which would make it jump and transition out of thumb mode and crash since you
only have thumb mode on such cores.
Now it correctly generates
Hex dump of section '.got':
...
0x000101b8 40010100 00000000 00000000 11010000 @...............
build on native hardware and regtested on
arm-none-elf, arm-none-elf (32 bit host),
arm-none-linux-gnueabihf, arm-none-linux-gnueabihf (32 bit host)
Cross-compiled and regtested on
arm-none-linux-gnueabihf, armeb-none-elf, arm-wince-pe
and no issues.
However I have not been able to do an execution test since I do not have a way
to actually test this. I am hoping the user who reported it can test it but the
patch is sound based on principles.
Amol would you be able to confirm the patch works on your setup?
Ok for master? and for backport to binutils-2.34?
Thanks,
Tamar
bfd/ChangeLog:
2020-03-30 Tamar Christina <tamar.christina@arm.com>
PR ld/16017
* elf32-arm.c (elf32_arm_populate_plt_entry): Set LSB of the PLT0
address in the GOT if in thumb only mode.
ld/ChangeLog:
2020-03-30 Tamar Christina <tamar.christina@arm.com>
PR ld/16017
* testsuite/ld-arm/arm-elf.exp (thumb-plt-got): New.
* testsuite/ld-arm/thumb-plt-got.d: New test.
--
[-- Attachment #2: rb12844.patch --]
[-- Type: text/x-diff, Size: 1878 bytes --]
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 0036ff96e593456e602c47775f1695fc0e629ea7..02d43a86195bd527fec24c845c2e925bc5a45346 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -10001,6 +10001,12 @@ elf32_arm_populate_plt_entry (bfd *output_bfd, struct bfd_link_info *info,
rel.r_info = ELF32_R_INFO (dynindx, R_ARM_JUMP_SLOT);
initial_got_entry = (splt->output_section->vma
+ splt->output_offset);
+
+ /* PR ld/16017
+ When thumb only we need to set the LSB for any address that
+ will be used with an interworking branch instruction. */
+ if (using_thumb_only (htab))
+ initial_got_entry |= 1;
}
}
diff --git a/ld/testsuite/ld-arm/arm-elf.exp b/ld/testsuite/ld-arm/arm-elf.exp
index 99a313999e7327fbeb0c344af4a66d2ee73771b6..59e68de800bdcd53b51fd44b28972e53f7f141c8 100644
--- a/ld/testsuite/ld-arm/arm-elf.exp
+++ b/ld/testsuite/ld-arm/arm-elf.exp
@@ -1270,3 +1270,4 @@ run_dump_test "non-contiguous-arm5"
run_dump_test "non-contiguous-arm6"
run_dump_test "thumb-plt"
+run_dump_test "thumb-plt-got"
diff --git a/ld/testsuite/ld-arm/thumb-plt-got.d b/ld/testsuite/ld-arm/thumb-plt-got.d
new file mode 100644
index 0000000000000000000000000000000000000000..e65aba9e2f8a3129990166c458d7c82306e1af7b
--- /dev/null
+++ b/ld/testsuite/ld-arm/thumb-plt-got.d
@@ -0,0 +1,14 @@
+#source: thumb-plt.s
+#name: Thumb only PLT and GOT LSB Symbol
+#ld: -shared -e0
+#readelf: -rx .got
+#skip: *-*-pe *-*-wince *-*-vxworks armeb-*-* *-*-gnueabihf
+
+Relocation section '.rel.plt' at offset 0x108 contains 1 entry:
+ Offset Info Type Sym.Value Sym. Name
+000101c4 00000116 R_ARM_JUMP_SLOT 00000000 foo
+
+Hex dump of section '.got':
+ NOTE: This section has relocations against it, but these have NOT been applied to this dump.
+ 0x000101b8 40010100 00000000 00000000 11010000 @...............
+
next reply other threads:[~2020-03-30 8:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-30 8:12 Tamar Christina [this message]
2020-03-30 9:28 ` Nick Clifton
2020-03-31 10:43 ` Amol
2020-04-01 9:28 ` Tamar Christina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200330081219.GA16551@arm.com \
--to=tamar.christina@arm.com \
--cc=Richard.Earnshaw@arm.com \
--cc=binutils@sourceware.org \
--cc=nd@arm.com \
--cc=nickc@redhat.com \
--cc=ramana.radhakrishnan@arm.com \
--cc=suratiamol@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).