aboutsummaryrefslogtreecommitdiff
path: root/libctf/testsuite/libctf-regression
diff options
context:
space:
mode:
Diffstat (limited to 'libctf/testsuite/libctf-regression')
-rw-r--r--libctf/testsuite/libctf-regression/nonstatic-var-section-ld-executable.lk9
-rw-r--r--libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r-ctf.c9
-rw-r--r--libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r.c73
-rw-r--r--libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r.lk7
-rw-r--r--libctf/testsuite/libctf-regression/nonstatic-var-section-ld.c76
-rw-r--r--libctf/testsuite/libctf-regression/nonstatic-var-section-ld.lk6
6 files changed, 180 insertions, 0 deletions
diff --git a/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-executable.lk b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-executable.lk
new file mode 100644
index 0000000..370a90c
--- /dev/null
+++ b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-executable.lk
@@ -0,0 +1,9 @@
+# lookup: nonstatic-var-section-ld.c
+# source: nonstatic-var-section-ld-r-ctf.c
+# nonshared: on
+# link: on
+# link_flags: -Wl,--ctf-variables
+foo is of type [0-9a-f]*
+bar is of type [0-9a-f]*
+foo missing from the data object section
+bar missing from the data object section
diff --git a/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r-ctf.c b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r-ctf.c
new file mode 100644
index 0000000..4712b1c
--- /dev/null
+++ b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r-ctf.c
@@ -0,0 +1,9 @@
+static int foo __attribute__((__used__));
+int bar;
+
+/* This is sometimes linked as a main program, sometimes via ld -r, and
+ sometimes via ld -shared. */
+int main (void)
+{
+ return 0;
+}
diff --git a/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r.c b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r.c
new file mode 100644
index 0000000..2fa761a
--- /dev/null
+++ b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r.c
@@ -0,0 +1,73 @@
+#include <ctf-api.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main (int argc, char *argv[])
+{
+ ctf_dict_t *fp;
+ ctf_archive_t *ctf;
+ ctf_id_t foo_type, bar_type, sym_type;
+ int found_foo = 0, found_bar = 0;
+ ctf_next_t *i = NULL;
+ const char *name;
+ int err;
+
+ if (argc != 2)
+ {
+ fprintf (stderr, "Syntax: %s PROGRAM\n", argv[0]);
+ exit(1);
+ }
+
+ if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL)
+ goto open_err;
+
+ if ((fp = ctf_dict_open (ctf, NULL, &err)) == NULL)
+ goto open_err;
+
+ /* Make sure we can look up both 'foo' and 'bar' as variables, even though one
+ of them is nonstatic: in a full link this should be erased, but this is an
+ ld -r link. */
+
+ if ((foo_type = ctf_lookup_variable (fp, "foo")) == CTF_ERR)
+ printf ("Cannot look up foo\n", ctf_errmsg (ctf_errno (fp)));
+ else
+ printf ("foo is of type %lx\n", foo_type);
+
+ if ((bar_type = ctf_lookup_variable (fp, "bar")) == CTF_ERR)
+ printf ("Cannot look up bar\n", ctf_errmsg (ctf_errno (fp)));
+ else
+ printf ("bar is of type %lx\n", bar_type);
+
+ /* Traverse the entire data object section and make sure it contains entries
+ for both foo and bar. (This is pure laziness: the section is small and
+ ctf_lookup_by_symbol_name does not yet exist.) */
+ while ((sym_type = ctf_symbol_next (fp, &i, &name, 0)) != CTF_ERR)
+ {
+ if (!name)
+ continue;
+
+ if (strcmp (name, "foo") == 0)
+ found_foo = 1;
+ if (strcmp (name, "bar") == 0)
+ found_bar = 1;
+ }
+ if (ctf_errno (fp) != ECTF_NEXT_END)
+ fprintf (stderr, "Unexpected error iterating over symbols: %s\n",
+ ctf_errmsg (ctf_errno (fp)));
+
+ if (!found_foo)
+ printf ("foo missing from the data object section\n");
+ if (!found_bar)
+ printf ("bar missing from the data object section\n");
+
+ ctf_dict_close (fp);
+ ctf_close (ctf);
+
+ return 0;
+
+ open_err:
+ fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err));
+ return 1;
+}
diff --git a/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r.lk b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r.lk
new file mode 100644
index 0000000..68c777f
--- /dev/null
+++ b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld-r.lk
@@ -0,0 +1,7 @@
+# source: nonstatic-var-section-ld-r-ctf.c
+# nonshared: on
+# link: on
+# link_flags: -Wl,--ctf-variables -r
+foo is of type [0-9a-f]*
+bar is of type [0-9a-f]*
+foo missing from the data object section
diff --git a/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.c b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.c
new file mode 100644
index 0000000..4e3a748
--- /dev/null
+++ b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.c
@@ -0,0 +1,76 @@
+#include <ctf-api.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main (int argc, char *argv[])
+{
+ ctf_dict_t *fp;
+ ctf_archive_t *ctf;
+ ctf_id_t foo_type, bar_type, sym_type;
+ int found_foo = 0, found_bar = 0;
+ ctf_next_t *i = NULL;
+ const char *name;
+ int err;
+
+ if (argc != 2)
+ {
+ fprintf (stderr, "Syntax: %s PROGRAM\n", argv[0]);
+ exit(1);
+ }
+
+ if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL)
+ goto open_err;
+
+ if ((fp = ctf_dict_open (ctf, NULL, &err)) == NULL)
+ goto open_err;
+
+ /* Make sure we can look up only 'foo' as a variable: bar, being nonstatic,
+ should have been erased. */
+
+ if ((foo_type = ctf_lookup_variable (fp, "foo")) == CTF_ERR)
+ printf ("Cannot look up foo\n", ctf_errmsg (ctf_errno (fp)));
+ else
+ printf ("foo is of type %lx\n", foo_type);
+
+ if ((bar_type = ctf_lookup_variable (fp, "bar")) == CTF_ERR)
+ printf ("Cannot look up bar\n", ctf_errmsg (ctf_errno (fp)));
+ else
+ printf ("bar is of type %lx\n", bar_type);
+
+ /* Traverse the entire data object section and make sure it contains an entry
+ for bar alone. (This is pure laziness: the section is small and
+ ctf_lookup_by_symbol_name does not yet exist.) */
+ while ((sym_type = ctf_symbol_next (fp, &i, &name, 0)) != CTF_ERR)
+ {
+ if (!name)
+ continue;
+
+ if (strcmp (name, "foo") == 0)
+ {
+ found_foo = 1;
+ printf ("Found foo in data object section with type %lx, "
+ "but it is static\n", sym_type);
+ }
+ if (strcmp (name, "bar") == 0)
+ found_bar = 1;
+ }
+ if (ctf_errno (fp) != ECTF_NEXT_END)
+ fprintf (stderr, "Unexpected error iterating over symbols: %s\n",
+ ctf_errmsg (ctf_errno (fp)));
+
+ if (!found_foo)
+ printf ("foo missing from the data object section\n");
+ if (!found_bar)
+ printf ("bar missing from the data object section\n");
+
+ ctf_dict_close (fp);
+ ctf_close (ctf);
+
+ return 0;
+
+ open_err:
+ fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err));
+ return 1;
+}
diff --git a/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.lk b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.lk
new file mode 100644
index 0000000..edb397a
--- /dev/null
+++ b/libctf/testsuite/libctf-regression/nonstatic-var-section-ld.lk
@@ -0,0 +1,6 @@
+# source: nonstatic-var-section-ld-r-ctf.c
+# link: on
+# link_flags: -Wl,--ctf-variables
+foo is of type [0-9a-f]*
+Cannot look up bar
+foo missing from the data object section