arm: Simplify elf_machine_{load_address,dynamic}
Checks
Context |
Check |
Description |
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
dj/TryBot-32bit |
success
|
Build for i686
|
Commit Message
and drop reliance on _GLOBAL_OFFSET_TABLE_[0] being the link-time
address of _DYNAMIC. &__ehdr_start is a better way to get the load address.
This is similar to commits b37b75d269883a2c553bb7019a813094eb4e2dd1
(x86-64) and 43d06ed218fc8be58987bdfd00e21e5720f0b862 (aarch64).
---
sysdeps/arm/dl-machine.h | 47 +++++++++-------------------------------
1 file changed, 10 insertions(+), 37 deletions(-)
Comments
On Tue, 17 Aug 2021, Fangrui Song via Libc-alpha wrote:
> and drop reliance on _GLOBAL_OFFSET_TABLE_[0] being the link-time
> address of _DYNAMIC. &__ehdr_start is a better way to get the load address.
OK.
Hi Fangrui ,Joseph,
> On Tue, 17 Aug 2021, Fangrui Song via Libc-alpha wrote:
>
> > and drop reliance on _GLOBAL_OFFSET_TABLE_[0] being the link-time
> > address of _DYNAMIC. &__ehdr_start is a better way to get the load
> > address.
>
> OK.
>
This commit causes very early OOPs on QEMU running kernel for ARM32 bit.
I've found this issue when developing and testing glibc ptests with the
newest glibc -master.
I'm going to debug this issue and share more info.
Reverting this patch (SHA1: bca0f5cbc9257c13322b99e55235c4f21ba0bd82)
causes the kernel to boot again.
The exact error is attached.
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
[ 3.972443] Run /sbin/init as init process
[ 4.047873] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[ 4.048465] CPU: 1 PID: 1 Comm: init Not tainted 5.1.21-y2038-4a9b1eb8bc3ba4ad8b3b1aa3317cf8d4a3aaad83 #1
[ 4.048860] Hardware name: ARM-Versatile Express
[ 4.049900] [<80110598>] (unwind_backtrace) from [<8010c1e4>] (show_stack+0x10/0x14)
[ 4.050165] [<8010c1e4>] (show_stack) from [<80712438>] (dump_stack+0x80/0x94)
[ 4.050337] [<80712438>] (dump_stack) from [<80120598>] (panic+0x10c/0x2cc)
[ 4.050575] [<80120598>] (panic) from [<80124884>] (do_exit+0x9ec/0xa74)
[ 4.050734] [<80124884>] (do_exit) from [<8012572c>] (do_group_exit+0x3c/0xd0)
[ 4.050903] [<8012572c>] (do_group_exit) from [<80131818>] (get_signal+0x168/0x89c)
[ 4.051074] [<80131818>] (get_signal) from [<8010b7fc>] (do_work_pending+0x114/0x584)
[ 4.051250] [<8010b7fc>] (do_work_pending) from [<8010106c>] (slow_work_pending+0xc/0x20)
[ 4.051498] Exception stack(0xbf0b3fb0 to 0xbf0b3ff8)
[ 4.051743] 3fa0: b7fd2964 b7fd296c b7fd28ec b7fd28e4
[ 4.052025] 3fc0: b7fd295c 76fd2000 76ffef84 7eb36ec0 6ffffeff 6fffff41 b7fd2994 00000000
[ 4.052283] 3fe0: b7fd2994 7eb36eb8 00000028 76fd3360 80000030 ffffffff
[ 4.052758] CPU0: stopping
[ 4.052850] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.1.21-y2038-4a9b1eb8bc3ba4ad8b3b1aa3317cf8d4a3aaad83 #1
[ 4.053046] Hardware name: ARM-Versatile Express
[ 4.053169] [<80110598>] (unwind_backtrace) from [<8010c1e4>] (show_stack+0x10/0x14)
[ 4.053337] [<8010c1e4>] (show_stack) from [<80712438>] (dump_stack+0x80/0x94)
[ 4.053490] [<80712438>] (dump_stack) from [<8010f264>] (handle_IPI+0x334/0x368)
[ 4.053656] [<8010f264>] (handle_IPI) from [<80448758>] (gic_handle_irq+0x8c/0x90)
[ 4.053817] [<80448758>] (gic_handle_irq) from [<80101a8c>] (__irq_svc+0x6c/0x90)
[ 4.053970] Exception stack(0x80b01f10 to 0x80b01f58)
[ 4.054132] 1f00: 00000000 00000000 000047f8 801190c0
[ 4.054384] 1f20: 00000000 80b00000 00000000 00000000 80b08c30 80b08c6c 80a69950 80b01f68
[ 4.054594] 1f40: 00000000 80b01f60 80108c20 80108c24 60000013 ffffffff
[ 4.054760] [<80101a8c>] (__irq_svc) from [<80108c24>] (arch_cpu_idle+0x38/0x3c)
[ 4.054922] [<80108c24>] (arch_cpu_idle) from [<801500c0>] (do_idle+0x214/0x288)
[ 4.055119] [<801500c0>] (do_idle) from [<801503dc>] (cpu_startup_entry+0x18/0x1c)
[ 4.055343] [<801503dc>] (cpu_startup_entry) from [<80a00e64>] (start_kernel+0x454/0x48c)
[ 4.055971] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---
@@ -37,48 +37,21 @@ elf_machine_matches_host (const Elf32_Ehdr *ehdr)
return ehdr->e_machine == EM_ARM;
}
-
-/* Return the link-time address of _DYNAMIC. Conveniently, this is the
- first element of the GOT. */
-static inline Elf32_Addr __attribute__ ((unused))
-elf_machine_dynamic (void)
-{
- /* Declaring this hidden ensures that a PC-relative reference is used. */
- extern const Elf32_Addr _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
- return _GLOBAL_OFFSET_TABLE_[0];
-}
-
-
/* Return the run-time load address of the shared object. */
-static inline Elf32_Addr __attribute__ ((unused))
+static inline ElfW(Addr) __attribute__ ((unused))
elf_machine_load_address (void)
{
- Elf32_Addr pcrel_addr;
-#ifdef SHARED
- extern Elf32_Addr __dl_start (void *) asm ("_dl_start");
- Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
- asm ("adr %0, _dl_start" : "=r" (pcrel_addr));
-#else
- extern Elf32_Addr __dl_relocate_static_pie (void *)
- asm ("_dl_relocate_static_pie") attribute_hidden;
- Elf32_Addr got_addr = (Elf32_Addr) &__dl_relocate_static_pie;
- asm ("adr %0, _dl_relocate_static_pie" : "=r" (pcrel_addr));
-#endif
-#ifdef __thumb__
- /* Clear the low bit of the function address.
-
- NOTE: got_addr is from GOT table whose lsb is always set by linker if it's
- Thumb function address. PCREL_ADDR comes from PC-relative calculation
- which will finish during assembling. GAS assembler before the fix for
- PR gas/21458 was not setting the lsb but does after that. Always do the
- strip for both, so the code works with various combinations of glibc and
- Binutils. */
- got_addr &= ~(Elf32_Addr) 1;
- pcrel_addr &= ~(Elf32_Addr) 1;
-#endif
- return pcrel_addr - got_addr;
+ extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
+ return (ElfW(Addr)) &__ehdr_start;
}
+/* Return the link-time address of _DYNAMIC. */
+static inline ElfW(Addr) __attribute__ ((unused))
+elf_machine_dynamic (void)
+{
+ extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
+ return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address ();
+}
/* Set up the loaded object described by L so its unrelocated PLT
entries will jump to the on-demand fixup code in dl-runtime.c. */