public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/maskray/lld] csu: Skip ARCH_SETUP_IREL if _dl_relocate_static_pie applied IRELATIVE relocations
@ 2021-01-29 18:44 Fangrui Song
0 siblings, 0 replies; 3+ messages in thread
From: Fangrui Song @ 2021-01-29 18:44 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=94ccdb2377950acbb52e284117f333c8d3fc6401
commit 94ccdb2377950acbb52e284117f333c8d3fc6401
Author: Siva Chandra Reddy <sivachandra@google.com>
Date: Fri Jan 29 10:42:50 2021 -0800
csu: Skip ARCH_SETUP_IREL if _dl_relocate_static_pie applied IRELATIVE relocations
For static pie, _dl_relocate_static_pie applies IRELATIVE relocations so
ARCH_SETUP_IREL should not apply relocations again.
LLD defines __rela_iplt_start/__rela_iplt_end regardless of -no-pie or
-pie, so in an LLD linked static pie, ARCH_SETUP_IREL would otherwise
apply the relocations in the range of [__rela_iplt_start,
__rela_iplt_end).
Co-authored-by: Fangrui Song <maskray@google.com>
Diff:
---
csu/libc-start.c | 8 +++++---
csu/static-reloc.c | 3 ++-
elf/dl-reloc-static-pie.c | 4 +++-
sysdeps/generic/ldsodefs.h | 4 ++--
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/csu/libc-start.c b/csu/libc-start.c
index feb0d7ce11..44d9d875d2 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -200,10 +200,11 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
/* Do static pie self relocation after tunables and cpu features
are setup for ifunc resolvers. Before this point relocations
must be avoided. */
- _dl_relocate_static_pie ();
+ int irel_applied = _dl_relocate_static_pie ();
/* Perform IREL{,A} relocations. */
- ARCH_SETUP_IREL ();
+ if (!irel_applied)
+ ARCH_SETUP_IREL ();
/* The stack guard goes into the TCB, so initialize it early. */
ARCH_SETUP_TLS ();
@@ -211,7 +212,8 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
/* In some architectures, IREL{,A} relocations happen after TLS setup in
order to let IFUNC resolvers benefit from TCB information, e.g. powerpc's
hwcap and platform fields available in the TCB. */
- ARCH_APPLY_IREL ();
+ if (!irel_applied)
+ ARCH_APPLY_IREL ();
/* Set up the stack checker's canary. */
uintptr_t stack_chk_guard = _dl_setup_stack_chk_guard (_dl_random);
diff --git a/csu/static-reloc.c b/csu/static-reloc.c
index 972c524f28..9046d9f6a3 100644
--- a/csu/static-reloc.c
+++ b/csu/static-reloc.c
@@ -19,8 +19,9 @@
#if ENABLE_STATIC_PIE
#include <ldsodefs.h>
-void
+int
_dl_relocate_static_pie (void)
{
+ return 0;
}
#endif
diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c
index d5bd2f31e9..b707ef4bf1 100644
--- a/elf/dl-reloc-static-pie.c
+++ b/elf/dl-reloc-static-pie.c
@@ -25,7 +25,7 @@
/* Relocate static executable with PIE. */
-void
+int
_dl_relocate_static_pie (void)
{
struct link_map *main_map = _dl_get_dl_main_map ();
@@ -66,5 +66,7 @@ _dl_relocate_static_pie (void)
with the run-time address of the r_debug structure */
main_map->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
# endif
+
+ return 1;
}
#endif
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index aab7245e93..a0b1e3a34e 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -1148,13 +1148,13 @@ void __libc_setup_tls (void);
# if ENABLE_STATIC_PIE
/* Relocate static executable with PIE. */
-extern void _dl_relocate_static_pie (void) attribute_hidden;
+extern int _dl_relocate_static_pie (void) attribute_hidden;
/* Get a pointer to _dl_main_map. */
extern struct link_map * _dl_get_dl_main_map (void)
__attribute__ ((visibility ("hidden")));
# else
-# define _dl_relocate_static_pie()
+# define _dl_relocate_static_pie() 0
# endif
#endif
^ permalink raw reply [flat|nested] 3+ messages in thread
* [glibc/maskray/lld] csu: Skip ARCH_SETUP_IREL if _dl_relocate_static_pie applied IRELATIVE relocations
@ 2021-02-01 17:23 Fangrui Song
0 siblings, 0 replies; 3+ messages in thread
From: Fangrui Song @ 2021-02-01 17:23 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0d59a02ab21b9770805a70783511b3d46b577af1
commit 0d59a02ab21b9770805a70783511b3d46b577af1
Author: Siva Chandra Reddy <sivachandra@google.com>
Date: Fri Jan 29 10:42:50 2021 -0800
csu: Skip ARCH_SETUP_IREL if _dl_relocate_static_pie applied IRELATIVE relocations
For static pie, _dl_relocate_static_pie applies IRELATIVE relocations so
ARCH_SETUP_IREL should not apply relocations again.
LLD defines __rela_iplt_start/__rela_iplt_end regardless of -no-pie or
-pie, so in an LLD linked static pie, ARCH_SETUP_IREL would otherwise
apply the relocations in the range of [__rela_iplt_start,
__rela_iplt_end).
Co-authored-by: Fangrui Song <maskray@google.com>
Diff:
---
csu/libc-start.c | 8 +++++---
csu/static-reloc.c | 3 ++-
elf/dl-reloc-static-pie.c | 4 +++-
sysdeps/generic/ldsodefs.h | 4 ++--
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/csu/libc-start.c b/csu/libc-start.c
index feb0d7ce11..44d9d875d2 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -200,10 +200,11 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
/* Do static pie self relocation after tunables and cpu features
are setup for ifunc resolvers. Before this point relocations
must be avoided. */
- _dl_relocate_static_pie ();
+ int irel_applied = _dl_relocate_static_pie ();
/* Perform IREL{,A} relocations. */
- ARCH_SETUP_IREL ();
+ if (!irel_applied)
+ ARCH_SETUP_IREL ();
/* The stack guard goes into the TCB, so initialize it early. */
ARCH_SETUP_TLS ();
@@ -211,7 +212,8 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
/* In some architectures, IREL{,A} relocations happen after TLS setup in
order to let IFUNC resolvers benefit from TCB information, e.g. powerpc's
hwcap and platform fields available in the TCB. */
- ARCH_APPLY_IREL ();
+ if (!irel_applied)
+ ARCH_APPLY_IREL ();
/* Set up the stack checker's canary. */
uintptr_t stack_chk_guard = _dl_setup_stack_chk_guard (_dl_random);
diff --git a/csu/static-reloc.c b/csu/static-reloc.c
index 972c524f28..9046d9f6a3 100644
--- a/csu/static-reloc.c
+++ b/csu/static-reloc.c
@@ -19,8 +19,9 @@
#if ENABLE_STATIC_PIE
#include <ldsodefs.h>
-void
+int
_dl_relocate_static_pie (void)
{
+ return 0;
}
#endif
diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c
index d5bd2f31e9..b707ef4bf1 100644
--- a/elf/dl-reloc-static-pie.c
+++ b/elf/dl-reloc-static-pie.c
@@ -25,7 +25,7 @@
/* Relocate static executable with PIE. */
-void
+int
_dl_relocate_static_pie (void)
{
struct link_map *main_map = _dl_get_dl_main_map ();
@@ -66,5 +66,7 @@ _dl_relocate_static_pie (void)
with the run-time address of the r_debug structure */
main_map->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
# endif
+
+ return 1;
}
#endif
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index aab7245e93..a0b1e3a34e 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -1148,13 +1148,13 @@ void __libc_setup_tls (void);
# if ENABLE_STATIC_PIE
/* Relocate static executable with PIE. */
-extern void _dl_relocate_static_pie (void) attribute_hidden;
+extern int _dl_relocate_static_pie (void) attribute_hidden;
/* Get a pointer to _dl_main_map. */
extern struct link_map * _dl_get_dl_main_map (void)
__attribute__ ((visibility ("hidden")));
# else
-# define _dl_relocate_static_pie()
+# define _dl_relocate_static_pie() 0
# endif
#endif
^ permalink raw reply [flat|nested] 3+ messages in thread
* [glibc/maskray/lld] csu: Skip ARCH_SETUP_IREL if _dl_relocate_static_pie applied IRELATIVE relocations
@ 2021-02-01 18:01 Fangrui Song
0 siblings, 0 replies; 3+ messages in thread
From: Fangrui Song @ 2021-02-01 18:01 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c67127a88540f6de4b92370158b5da61bec23f4f
commit c67127a88540f6de4b92370158b5da61bec23f4f
Author: Siva Chandra Reddy <sivachandra@google.com>
Date: Fri Jan 29 10:42:50 2021 -0800
csu: Skip ARCH_SETUP_IREL if _dl_relocate_static_pie applied IRELATIVE relocations
For static pie, _dl_relocate_static_pie applies IRELATIVE relocations so
ARCH_SETUP_IREL should not apply relocations again.
LLD defines __rela_iplt_start/__rela_iplt_end regardless of -no-pie or
-pie, so in an LLD linked static pie, ARCH_SETUP_IREL would otherwise
apply the relocations in the range of [__rela_iplt_start,
__rela_iplt_end).
Co-authored-by: Fangrui Song <maskray@google.com>
Diff:
---
csu/libc-start.c | 8 +++++---
csu/static-reloc.c | 3 ++-
elf/dl-reloc-static-pie.c | 4 +++-
sysdeps/generic/ldsodefs.h | 4 ++--
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/csu/libc-start.c b/csu/libc-start.c
index feb0d7ce11..44d9d875d2 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -200,10 +200,11 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
/* Do static pie self relocation after tunables and cpu features
are setup for ifunc resolvers. Before this point relocations
must be avoided. */
- _dl_relocate_static_pie ();
+ int irel_applied = _dl_relocate_static_pie ();
/* Perform IREL{,A} relocations. */
- ARCH_SETUP_IREL ();
+ if (!irel_applied)
+ ARCH_SETUP_IREL ();
/* The stack guard goes into the TCB, so initialize it early. */
ARCH_SETUP_TLS ();
@@ -211,7 +212,8 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
/* In some architectures, IREL{,A} relocations happen after TLS setup in
order to let IFUNC resolvers benefit from TCB information, e.g. powerpc's
hwcap and platform fields available in the TCB. */
- ARCH_APPLY_IREL ();
+ if (!irel_applied)
+ ARCH_APPLY_IREL ();
/* Set up the stack checker's canary. */
uintptr_t stack_chk_guard = _dl_setup_stack_chk_guard (_dl_random);
diff --git a/csu/static-reloc.c b/csu/static-reloc.c
index 972c524f28..9046d9f6a3 100644
--- a/csu/static-reloc.c
+++ b/csu/static-reloc.c
@@ -19,8 +19,9 @@
#if ENABLE_STATIC_PIE
#include <ldsodefs.h>
-void
+int
_dl_relocate_static_pie (void)
{
+ return 0;
}
#endif
diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c
index d5bd2f31e9..b707ef4bf1 100644
--- a/elf/dl-reloc-static-pie.c
+++ b/elf/dl-reloc-static-pie.c
@@ -25,7 +25,7 @@
/* Relocate static executable with PIE. */
-void
+int
_dl_relocate_static_pie (void)
{
struct link_map *main_map = _dl_get_dl_main_map ();
@@ -66,5 +66,7 @@ _dl_relocate_static_pie (void)
with the run-time address of the r_debug structure */
main_map->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;
# endif
+
+ return 1;
}
#endif
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index aab7245e93..a0b1e3a34e 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -1148,13 +1148,13 @@ void __libc_setup_tls (void);
# if ENABLE_STATIC_PIE
/* Relocate static executable with PIE. */
-extern void _dl_relocate_static_pie (void) attribute_hidden;
+extern int _dl_relocate_static_pie (void) attribute_hidden;
/* Get a pointer to _dl_main_map. */
extern struct link_map * _dl_get_dl_main_map (void)
__attribute__ ((visibility ("hidden")));
# else
-# define _dl_relocate_static_pie()
+# define _dl_relocate_static_pie() 0
# endif
#endif
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-01 18:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-29 18:44 [glibc/maskray/lld] csu: Skip ARCH_SETUP_IREL if _dl_relocate_static_pie applied IRELATIVE relocations Fangrui Song
2021-02-01 17:23 Fangrui Song
2021-02-01 18:01 Fangrui Song
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).