diff mbox

[uclibc-ng-devel,v2,2/2] ARC: ldso: don't use _DYNAMIC@gotpc construct #2

Message ID 1484339093-16814-3-git-send-email-vgupta@synopsys.com
State Accepted
Headers show

Commit Message

Vineet Gupta Jan. 13, 2017, 8:24 p.m. UTC
This removes _DYNAMIC@gotpc from elf_machine_load_address()
This is a seperate commit to callout the fact that old code was actually
broken but was NOT caught since it never gets called (and will never be)
since ld.so only calls it if kernel doesn't pass AT_BASE auxvt, which is
not true for Linux.

    if (!auxvt[AT_BASE].a_un.a_val)
		auxvt[AT_BASE].a_un.a_val = elf_machine_load_address();

So while the intent was to remove _DYNAMIC@gotpc construct, we need to
come up with something which works.

The build time address computation of .dynamic which works well is:

-	"ld  %1, [pcl, _DYNAMIC@gotpc]			\n"
+	"ld  %1, [pcl, _GLOBAL_OFFSET_TABLE_@pcl]	\n"

However the runtime address of .dynamic can only be generated with

        "add %0, pcl, _DYNAMIC@pcl     		\n"

which unfortunately is what is currently broken as it is converted to
i_GLOBAL_OFFSET_TABLE_t and thus refers to runtime address of .got and
not .dyanmic

Thus we resort to using an arbit symbol _dl_start at the expense of an
extra GOT entry and a bogus R_ARC_NONE relo in ldso itself which now
needs to be ignored.

Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
---
 ldso/ldso/arc/dl-startup.h | 2 +-
 ldso/ldso/arc/dl-sysdep.h  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/ldso/ldso/arc/dl-startup.h b/ldso/ldso/arc/dl-startup.h
index 232ecb975b29..dbce2f0c9a2b 100644
--- a/ldso/ldso/arc/dl-startup.h
+++ b/ldso/ldso/arc/dl-startup.h
@@ -74,7 +74,7 @@  do {									\
 		*REL += (unsigned long) LOAD;				\
 	else if (type == R_ARC_JMP_SLOT)                                \
 		*REL = SYMBOL;						\
-	else								\
+	else if (type != R_ARC_NONE)					\
 		_dl_exit(1);						\
 }while(0)
 
diff --git a/ldso/ldso/arc/dl-sysdep.h b/ldso/ldso/arc/dl-sysdep.h
index 2b43efde594b..ed8b37205cc4 100644
--- a/ldso/ldso/arc/dl-sysdep.h
+++ b/ldso/ldso/arc/dl-sysdep.h
@@ -144,8 +144,8 @@  static __always_inline Elf32_Addr elf_machine_load_address(void)
      */
 	Elf32_Addr addr, tmp;
 	__asm__ (
-        "ld  %1, [pcl, _DYNAMIC@gotpc] ;build addr of _DYNAMIC"   "\n"
-        "add %0, pcl, _DYNAMIC@pcl     ;runtime addr of _DYNAMIC" "\n"
+        "ld  %1, [pcl, _dl_start@gotpc] ;build addr of _DYNAMIC"   "\n"
+        "add %0, pcl, _dl_start@pcl     ;runtime addr of _DYNAMIC" "\n"
         "sub %0, %0, %1                ;delta"                    "\n"
         : "=&r" (addr), "=r"(tmp)
     );