aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2024-07-16 13:01:36 +0100
committerNick Alcock <nick.alcock@oracle.com>2024-11-18 11:50:10 +0000
commit7b164967263bb5c2387d547a241777c89c873ab4 (patch)
tree29716c8a31ead2cddc26c624d351c4dccbd4b983
parent5417ad0f2e632f9c4a7d1f2a420c71b53c12f2dc (diff)
downloadbinutils-7b164967263bb5c2387d547a241777c89c873ab4.zip
binutils-7b164967263bb5c2387d547a241777c89c873ab4.tar.gz
binutils-7b164967263bb5c2387d547a241777c89c873ab4.tar.bz2
libctf: a little string sharing test
It's actually quite hard to come up with simple tests that do *not* share all their strings, but with enough ingenuity suitable cycles can be concocted. This test verifies that only and precisely those strings that are only used in one child dict actually end up in its strtab. ld/ * testsuite/ld-ctf/unshared-strings*: New test.
-rw-r--r--ld/testsuite/ld-ctf/unshared-strings-A.c19
-rw-r--r--ld/testsuite/ld-ctf/unshared-strings-B.c21
-rw-r--r--ld/testsuite/ld-ctf/unshared-strings.d45
3 files changed, 85 insertions, 0 deletions
diff --git a/ld/testsuite/ld-ctf/unshared-strings-A.c b/ld/testsuite/ld-ctf/unshared-strings-A.c
new file mode 100644
index 0000000..690f129
--- /dev/null
+++ b/ld/testsuite/ld-ctf/unshared-strings-A.c
@@ -0,0 +1,19 @@
+struct A;
+struct B
+{
+ int foo;
+ struct A *a;
+};
+struct C;
+typedef struct C aaa;
+struct A
+{
+ aaa *wurblefrotz;
+};
+struct C
+{
+ struct B *foo;
+};
+
+static struct A *foo __attribute__((used));
+
diff --git a/ld/testsuite/ld-ctf/unshared-strings-B.c b/ld/testsuite/ld-ctf/unshared-strings-B.c
new file mode 100644
index 0000000..51796cc
--- /dev/null
+++ b/ld/testsuite/ld-ctf/unshared-strings-B.c
@@ -0,0 +1,21 @@
+struct A;
+struct B
+{
+ int foo;
+ struct A *a;
+};
+struct C;
+typedef struct C C1;
+typedef C1 C2;
+struct A
+{
+ C2 *wurblefritz;
+};
+
+struct C
+{
+ struct B *foo;
+};
+
+static struct A *foo __attribute__((used));
+
diff --git a/ld/testsuite/ld-ctf/unshared-strings.d b/ld/testsuite/ld-ctf/unshared-strings.d
new file mode 100644
index 0000000..32bed29
--- /dev/null
+++ b/ld/testsuite/ld-ctf/unshared-strings.d
@@ -0,0 +1,45 @@
+#as:
+#source: unshared-strings-A.c
+#source: unshared-strings-B.c
+#objdump: --ctf
+#ld: -shared
+#name: Verify proper sharing (and non-sharing) of strings
+
+.*: +file format .*
+
+Contents of CTF section .ctf:
+
+ Header:
+ Magic number: 0xdff2
+ Version: 5 \(CTF_VERSION_4\)
+#...
+ Strings:
+ 0x0:
+ 0x[0-9a-f]*: A
+#...
+ 0x[0-9a-f]*: C1
+ 0x[0-9a-f]*: C2
+#...
+ 0x[0-9a-f]*: aaa
+#...
+CTF archive member: .*/unshared-strings-A.c:
+#...
+ Types:
+ 0x[0-9a-f]*: \(kind 6\) struct A .*
+ \[0x0\] wurblefrotz: ID .*
+
+ Strings:
+ 0x0: .ctf
+#...
+ 0x[0-9a-f]*: wurblefrotz
+
+CTF archive member: .*/unshared-strings-B.c:
+#...
+ Types:
+ 0x[0-9a-f]*: \(kind 6\) struct A .*
+ \[0x0\] wurblefritz: ID .*
+
+ Strings:
+ 0x0: .ctf
+#...
+ 0x[0-9a-f]*: wurblefritz