public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/maskray/lld] Make _dl_relocate_static_pie return an int indicating whether it applied relocs.
@ 2021-01-18 21:38 Fangrui Song
0 siblings, 0 replies; 3+ messages in thread
From: Fangrui Song @ 2021-01-18 21:38 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=de5e0f3ed6c375de2123e1be3cd582ec408e1210
commit de5e0f3ed6c375de2123e1be3cd582ec408e1210
Author: Siva Chandra Reddy <sivachandra@google.com>
Date: Mon Dec 28 13:36:12 2020 -0800
Make _dl_relocate_static_pie return an int indicating whether it applied relocs.
There are two versions of _dl_relocation_static_pie. One of them is the
actual worker used for static pie which applies the startup relocations.
The other is a dummy use for non-pie static. This change make the worker
version return 1, and the dummy version return 0. The return value 1
indicates that the relocs have been applied, and hence a second round of
irel relocations are not attempted in LIBC_START_MAIN for static-pie.
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 db859c3bed..a4f45a3d0e 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -142,7 +142,7 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
int result;
#ifndef SHARED
- _dl_relocate_static_pie ();
+ int irel_applied = _dl_relocate_static_pie ();
char **ev = &argv[argc + 1];
@@ -192,7 +192,8 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
ARCH_INIT_CPU_FEATURES ();
/* 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 ();
@@ -200,7 +201,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 a8d964061e..4f87125d50 100644
--- a/elf/dl-reloc-static-pie.c
+++ b/elf/dl-reloc-static-pie.c
@@ -23,7 +23,7 @@
/* Relocate static executable with PIE. */
-void
+int
_dl_relocate_static_pie (void)
{
struct link_map *main_map = _dl_get_dl_main_map ();
@@ -64,5 +64,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] Make _dl_relocate_static_pie return an int indicating whether it applied relocs.
@ 2021-01-18 21:41 Fangrui Song
0 siblings, 0 replies; 3+ messages in thread
From: Fangrui Song @ 2021-01-18 21:41 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=be2a3eb72311fd7237b510bd6a1808a72d9ad4e5
commit be2a3eb72311fd7237b510bd6a1808a72d9ad4e5
Author: Siva Chandra Reddy <sivachandra@google.com>
Date: Mon Dec 28 13:36:12 2020 -0800
Make _dl_relocate_static_pie return an int indicating whether it applied relocs.
There are two versions of _dl_relocation_static_pie. One of them is the
actual worker used for static pie which applies the startup relocations.
The other is a dummy use for non-pie static. This change make the worker
version return 1, and the dummy version return 0. The return value 1
indicates that the relocs have been applied, and hence a second round of
irel relocations are not attempted in LIBC_START_MAIN for static-pie.
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 db859c3bed..a4f45a3d0e 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -142,7 +142,7 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
int result;
#ifndef SHARED
- _dl_relocate_static_pie ();
+ int irel_applied = _dl_relocate_static_pie ();
char **ev = &argv[argc + 1];
@@ -192,7 +192,8 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
ARCH_INIT_CPU_FEATURES ();
/* 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 ();
@@ -200,7 +201,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 a8d964061e..4f87125d50 100644
--- a/elf/dl-reloc-static-pie.c
+++ b/elf/dl-reloc-static-pie.c
@@ -23,7 +23,7 @@
/* Relocate static executable with PIE. */
-void
+int
_dl_relocate_static_pie (void)
{
struct link_map *main_map = _dl_get_dl_main_map ();
@@ -64,5 +64,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] Make _dl_relocate_static_pie return an int indicating whether it applied relocs.
@ 2020-12-28 21:38 Fangrui Song
0 siblings, 0 replies; 3+ messages in thread
From: Fangrui Song @ 2020-12-28 21:38 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=8a3fac6e49647cf68dfc848bd2178394c5340784
commit 8a3fac6e49647cf68dfc848bd2178394c5340784
Author: Siva Chandra Reddy <sivachandra@google.com>
Date: Mon Dec 28 13:36:12 2020 -0800
Make _dl_relocate_static_pie return an int indicating whether it applied relocs.
There are two versions of _dl_relocation_static_pie. One of them is the
actual worker used for static pie which applies the startup relocations.
The other is a dummy use for non-pie static. This change make the worker
version return 1, and the dummy version return 0. The return value 1
indicates that the relocs have been applied, and hence a second round of
irel relocations are not attempted in LIBC_START_MAIN for static-pie.
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 d330812c2d..5f13a0e3b2 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -142,7 +142,7 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
int result;
#ifndef SHARED
- _dl_relocate_static_pie ();
+ int irel_applied = _dl_relocate_static_pie ();
char **ev = &argv[argc + 1];
@@ -192,7 +192,8 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
ARCH_INIT_CPU_FEATURES ();
/* 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 ();
@@ -200,7 +201,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 b41a940142..2cd6f836ce 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 382482fa73..f2a6f8a7a1 100644
--- a/elf/dl-reloc-static-pie.c
+++ b/elf/dl-reloc-static-pie.c
@@ -23,7 +23,7 @@
/* Relocate static executable with PIE. */
-void
+int
_dl_relocate_static_pie (void)
{
struct link_map *main_map = _dl_get_dl_main_map ();
@@ -64,5 +64,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 933cda117d..d74888c6eb 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-01-18 21:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-18 21:38 [glibc/maskray/lld] Make _dl_relocate_static_pie return an int indicating whether it applied relocs Fangrui Song
-- strict thread matches above, loose matches on Subject: below --
2021-01-18 21:41 Fangrui Song
2020-12-28 21:38 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).