Merge "Make static ifunc resolvers optional."
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index 3219239..41f100d 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -67,9 +67,20 @@
}
#if defined(__aarch64__) || defined(__x86_64__)
-extern __LIBC_HIDDEN__ ElfW(Rela) __rela_iplt_start[], __rela_iplt_end[];
+extern __LIBC_HIDDEN__ __attribute__((weak)) ElfW(Rela) __rela_iplt_start[], __rela_iplt_end[];
static void call_ifunc_resolvers() {
+ if (__rela_iplt_start == nullptr || __rela_iplt_end == nullptr) {
+ // These symbols are not emitted by gold. Gold has code to do so, but for
+ // whatever reason it is not being run. In these cases ifuncs cannot be
+ // resolved, so we do not support using ifuncs in static executables linked
+ // with gold.
+ //
+ // Since they are weak, they will be non-null when linked with bfd/lld and
+ // null when linked with gold.
+ return;
+ }
+
typedef ElfW(Addr) (*ifunc_resolver_t)(void);
for (ElfW(Rela) *r = __rela_iplt_start; r != __rela_iplt_end; ++r) {
ElfW(Addr)* offset = reinterpret_cast<ElfW(Addr)*>(r->r_offset);
@@ -78,9 +89,20 @@
}
}
#else
-extern __LIBC_HIDDEN__ ElfW(Rel) __rel_iplt_start[], __rel_iplt_end[];
+extern __LIBC_HIDDEN__ __attribute__((weak)) ElfW(Rel) __rel_iplt_start[], __rel_iplt_end[];
static void call_ifunc_resolvers() {
+ if (__rel_iplt_start == nullptr || __rel_iplt_end == nullptr) {
+ // These symbols are not emitted by gold. Gold has code to do so, but for
+ // whatever reason it is not being run. In these cases ifuncs cannot be
+ // resolved, so we do not support using ifuncs in static executables linked
+ // with gold.
+ //
+ // Since they are weak, they will be non-null when linked with bfd/lld and
+ // null when linked with gold.
+ return;
+ }
+
typedef ElfW(Addr) (*ifunc_resolver_t)(void);
for (ElfW(Rel) *r = __rel_iplt_start; r != __rel_iplt_end; ++r) {
ElfW(Addr)* offset = reinterpret_cast<ElfW(Addr)*>(r->r_offset);