aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-elf
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2022-01-05 19:21:45 -0800
committerH.J. Lu <hjl.tools@gmail.com>2022-01-12 06:08:47 -0800
commit72aa81732b3aff00e5bf1f69bb794513b3b37464 (patch)
tree13cdfb51891320c3ff5b56652c50b499e2617c3c /ld/testsuite/ld-elf
parent4d9e2e53b9f93b0ae33ba948ae3d2825b3424441 (diff)
downloadfsf-binutils-gdb-72aa81732b3aff00e5bf1f69bb794513b3b37464.zip
fsf-binutils-gdb-72aa81732b3aff00e5bf1f69bb794513b3b37464.tar.gz
fsf-binutils-gdb-72aa81732b3aff00e5bf1f69bb794513b3b37464.tar.bz2
ld: Add glibc dependency for DT_RELR
When DT_RELR is enabled, to avoid random run-time crash with older glibc binaries without DT_RELR support, add a GLIBC_ABI_DT_RELR symbol version, which is provided by glibc with DT_RELR support, dependency on the shared C library if it provides a GLIBC_2.XX symbol version. bfd/ * elflink.c (elf_link_add_dt_relr_dependency): New function. (bfd_elf_size_dynamic_sections): Call elf_link_add_dt_relr_dependency if DT_RELR is enabled. ld/ * ld.texi: Mention GLIBC_ABI_DT_RELR in -z pack-relative-relocs entry. * testsuite/ld-elf/dt-relr-glibc-1.c: New file. * testsuite/ld-elf/dt-relr-glibc-1a.rd: Likewise. * testsuite/ld-elf/dt-relr-glibc-1b.rd: Likewise. * testsuite/ld-elf/dt-relr.exp: Likewise.
Diffstat (limited to 'ld/testsuite/ld-elf')
-rw-r--r--ld/testsuite/ld-elf/dt-relr-glibc-1.c11
-rw-r--r--ld/testsuite/ld-elf/dt-relr-glibc-1a.rd4
-rw-r--r--ld/testsuite/ld-elf/dt-relr-glibc-1b.rd7
-rw-r--r--ld/testsuite/ld-elf/dt-relr.exp44
4 files changed, 66 insertions, 0 deletions
diff --git a/ld/testsuite/ld-elf/dt-relr-glibc-1.c b/ld/testsuite/ld-elf/dt-relr-glibc-1.c
new file mode 100644
index 0000000..beacffe
--- /dev/null
+++ b/ld/testsuite/ld-elf/dt-relr-glibc-1.c
@@ -0,0 +1,11 @@
+#define REL(n) \
+ static int data##n; \
+ void *p##n = &data##n;
+
+REL(1)
+REL(2)
+REL(3)
+REL(4)
+REL(5)
+REL(6)
+REL(7)
diff --git a/ld/testsuite/ld-elf/dt-relr-glibc-1a.rd b/ld/testsuite/ld-elf/dt-relr-glibc-1a.rd
new file mode 100644
index 0000000..51bda5d
--- /dev/null
+++ b/ld/testsuite/ld-elf/dt-relr-glibc-1a.rd
@@ -0,0 +1,4 @@
+#failif
+#...
+ 0x[a-f0-9]+: Name: GLIBC_ABI_DT_RELR Flags: none Version: [0-9]+
+#...
diff --git a/ld/testsuite/ld-elf/dt-relr-glibc-1b.rd b/ld/testsuite/ld-elf/dt-relr-glibc-1b.rd
new file mode 100644
index 0000000..6556a6d
--- /dev/null
+++ b/ld/testsuite/ld-elf/dt-relr-glibc-1b.rd
@@ -0,0 +1,7 @@
+#...
+Version needs section '.gnu.version_r' contains 1 entry:
+ Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\)
+ +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+
+#...
+ 0x[a-f0-9]+: Name: GLIBC_ABI_DT_RELR Flags: none Version: [0-9]+
+#pass
diff --git a/ld/testsuite/ld-elf/dt-relr.exp b/ld/testsuite/ld-elf/dt-relr.exp
new file mode 100644
index 0000000..51d21e4
--- /dev/null
+++ b/ld/testsuite/ld-elf/dt-relr.exp
@@ -0,0 +1,44 @@
+# Expect script for DT_RELR.
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+
+# Linux tests.
+if { ![istarget "*-*-linux*"] } {
+ return
+}
+
+run_cc_link_tests [list \
+ [list \
+ "Build dt-relr-glibc-1a.so" \
+ "-shared $NO_DT_RELR_CC_LDFLAGS" \
+ "-fPIC" \
+ { dt-relr-glibc-1.c } \
+ {{readelf {--version-info} dt-relr-glibc-1a.rd}} \
+ "glibc-relr-1a.so" \
+ ] \
+ [list \
+ "Build dt-relr-glibc-1b.so" \
+ "-shared $DT_RELR_CC_LDFLAGS" \
+ "-fPIC" \
+ { dt-relr-glibc-1.c } \
+ {{readelf {-W --version-info} dt-relr-glibc-1b.rd}} \
+ "dt-relr-glibc-1b.so" \
+ ] \
+]