summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2016-07-08 14:08:22 +0200
committerMark Wielaard <[email protected]>2016-08-03 18:19:47 +0200
commitdd906c1b4852be4dd34924017261f89cc5c4c723 (patch)
tree6aac4ef30566095081089eed773711cf00e6e13d /tests
parente6ca75ddcf2ba9314077ddc9768eaac2405305e1 (diff)
dwelf: Add string table functions from ebl.
Move the strtab functions from libebl to libdw. Programs often want to create ELF/DWARF string tables. We don't want (static) linking against ebl since those are internal functions that might change. This introduces dwelf_strtab_init, dwelf_strtab_add, dwelf_strtab_add_len, dwelf_strtab_finalize, dwelf_strent_off, dwelf_strent_str and dwelf_strtab_free. Documentation for each has been added to libdwelf.h. The add fucntion got a variant that takes the length explicitly and finalize was changed to return NULL on out of memory instead of aborting. All code and tests now uses the new functions. Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog12
-rw-r--r--tests/Makefile.am8
-rw-r--r--tests/alldts.c24
-rw-r--r--tests/elfstrmerge.c31
-rw-r--r--tests/update3.c18
-rw-r--r--tests/update4.c42
6 files changed, 74 insertions, 61 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 8fe9ee86..58a023c2 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,15 @@
+2016-07-08 Mark Wielaard <[email protected]>
+
+ * update3_LDADD: Use libdw instead of libebl.
+ * update4_LDADD: Likewise.
+ * alldts_LDADD: Likewise.
+ * elfstrmerge_LDADD: Likewise.
+ * alldts.c (main): Use dwelf_strtab instead of ebl_strtab.
+ * elfstrmerge.c (release): Likewise.
+ (main): Likewise.
+ * update3.c (main): Likewise.
+ * update4.c (main): Likewise.
+
2016-07-10 Andreas Schwab <[email protected]>
* Makefile.am (TESTS): Add run-strip-test11.sh.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a64adca3..fcfb9358 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -406,8 +406,8 @@ early_offscn_LDADD = $(libelf)
ecp_LDADD = $(libelf)
update1_LDADD = $(libelf)
update2_LDADD = $(libelf)
-update3_LDADD = $(libebl) $(libelf)
-update4_LDADD = $(libebl) $(libelf)
+update3_LDADD = $(libdw) $(libelf)
+update4_LDADD = $(libdw) $(libelf)
show_die_info_LDADD = $(libdw) $(libelf)
get_pubnames_LDADD = $(libdw) $(libelf)
show_abbrev_LDADD = $(libdw) $(libelf)
@@ -445,7 +445,7 @@ dwarf_getstring_LDADD = $(libdw)
addrcfi_LDADD = $(libdw) $(libebl) $(libelf) $(argp_LDADD) -ldl
test_flag_nobits_LDADD = $(libelf)
rerequest_tag_LDADD = $(libdw)
-alldts_LDADD = $(libebl) $(libelf)
+alldts_LDADD = $(libdw) $(libelf)
md5_sha1_test_LDADD = $(libeu)
typeiter_LDADD = $(libdw) $(libelf)
typeiter2_LDADD = $(libdw) $(libelf)
@@ -478,7 +478,7 @@ elfstrtab_LDADD = $(libelf)
dwfl_proc_attach_LDADD = $(libdw)
dwfl_proc_attach_LDFLAGS = -pthread $(AM_LDFLAGS)
elfshphehdr_LDADD =$(libelf)
-elfstrmerge_LDADD = $(libebl) $(libelf)
+elfstrmerge_LDADD = $(libdw) $(libelf)
dwelfgnucompressed_LDADD = $(libelf) $(libdw)
elfgetchdr_LDADD = $(libelf) $(libdw)
elfgetzdata_LDADD = $(libelf)
diff --git a/tests/alldts.c b/tests/alldts.c
index eaecaf57..28b3063c 100644
--- a/tests/alldts.c
+++ b/tests/alldts.c
@@ -1,5 +1,5 @@
/* Create an ELF file with all the DT_* flags set.
- Copyright (C) 2011 Red Hat, Inc.
+ Copyright (C) 2011, 2016 Red Hat, Inc.
This file is part of elfutils.
Written by Marek Polacek <[email protected]>, 2011.
@@ -20,7 +20,7 @@
# include <config.h>
#endif
-#include ELFUTILS_HEADER(ebl)
+#include ELFUTILS_HEADER(dwelf)
#include <elf.h>
#include <gelf.h>
#include <fcntl.h>
@@ -38,9 +38,9 @@ int
main (void)
{
static const char fname[] = "testfile-alldts";
- struct Ebl_Strtab *shst;
- struct Ebl_Strent *dynscn;
- struct Ebl_Strent *shstrtabse;
+ Dwelf_Strtab *shst;
+ Dwelf_Strent *dynscn;
+ Dwelf_Strent *shstrtabse;
const Elf32_Sword dtflags[] =
{
DT_NULL, DT_NEEDED, DT_PLTRELSZ, DT_PLTGOT,
@@ -117,7 +117,7 @@ main (void)
phdr[1].p_type = PT_DYNAMIC;
elf_flagphdr (elf, ELF_C_SET, ELF_F_DIRTY);
- shst = ebl_strtabinit (true);
+ shst = dwelf_strtab_init (true);
/* Create the .dynamic section. */
Elf_Scn *scn = elf_newscn (elf);
@@ -134,7 +134,7 @@ main (void)
return 1;
}
- dynscn = ebl_strtabadd (shst, ".dynamic", 0);
+ dynscn = dwelf_strtab_add (shst, ".dynamic");
/* We'll need to know the section offset. But this will be set up
by elf_update later, so for now just store the address. */
@@ -191,7 +191,7 @@ main (void)
return 1;
}
- shstrtabse = ebl_strtabadd (shst, ".shstrtab", 0);
+ shstrtabse = dwelf_strtab_add (shst, ".shstrtab");
shdr->sh_type = SHT_STRTAB;
shdr->sh_flags = 0;
@@ -211,10 +211,10 @@ main (void)
}
/* No more sections, finalize the section header string table. */
- ebl_strtabfinalize (shst, data);
+ dwelf_strtab_finalize (shst, data);
- elf32_getshdr (elf_getscn (elf, 1))->sh_name = ebl_strtaboffset (dynscn);
- shdr->sh_name = ebl_strtaboffset (shstrtabse);
+ elf32_getshdr (elf_getscn (elf, 1))->sh_name = dwelf_strent_off (dynscn);
+ shdr->sh_name = dwelf_strent_off (shstrtabse);
/* Let the library compute the internal structure information. */
if (elf_update (elf, ELF_C_NULL) < 0)
@@ -251,7 +251,7 @@ main (void)
}
/* We don't need the string table anymore. */
- ebl_strtabfree (shst);
+ dwelf_strtab_free (shst);
/* And the data allocated in the .shstrtab section. */
free (data->d_buf);
diff --git a/tests/elfstrmerge.c b/tests/elfstrmerge.c
index 4149ca6e..c2c3fb97 100644
--- a/tests/elfstrmerge.c
+++ b/tests/elfstrmerge.c
@@ -1,5 +1,5 @@
/* Merge string sections.
- Copyright (C) 2015 Red Hat, Inc.
+ Copyright (C) 2015, 2016 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
@@ -30,7 +30,8 @@
#include <unistd.h>
#include <gelf.h>
-#include ELFUTILS_HEADER(ebl)
+#include ELFUTILS_HEADER(dwelf)
+#include "elf-knowledge.h"
/* The original ELF file. */
static int fd = -1;
@@ -43,13 +44,13 @@ static int fdnew = -1;
static Elf *elfnew = NULL;
/* The merged string table. */
-static struct Ebl_Strtab *strings = NULL;
+static Dwelf_Strtab *strings = NULL;
/* Section name strents. */
-static struct Ebl_Strent **scnstrents = NULL;
+static Dwelf_Strent **scnstrents = NULL;
/* Symbol name strends. */
-static struct Ebl_Strent **symstrents = NULL;
+static Dwelf_Strent **symstrents = NULL;
/* New ELF file buffers. */
static Elf_Data newstrtabdata = { .d_buf = NULL };
@@ -62,7 +63,7 @@ release (void)
{
/* The new string table. */
if (strings != NULL)
- ebl_strtabfree (strings);
+ dwelf_strtab_free (strings);
free (scnstrents);
free (symstrents);
@@ -241,7 +242,7 @@ main (int argc, char **argv)
bool layout = phnum != 0;
/* Create a new merged strings table that starts with the empty string. */
- strings = ebl_strtabinit (true);
+ strings = dwelf_strtab_init (true);
if (strings == NULL)
fail ("No memory to create merged string table", NULL);
@@ -249,7 +250,7 @@ main (int argc, char **argv)
size_t shdrnum;
if (elf_getshdrnum (elf, &shdrnum) != 0)
fail_elf ("Couldn't get number of sections", fname);
- scnstrents = malloc (shdrnum * sizeof (struct Ebl_Strent *));
+ scnstrents = malloc (shdrnum * sizeof (Dwelf_Strent *));
if (scnstrents == NULL)
fail ("couldn't allocate memory for section strings", NULL);
@@ -275,8 +276,8 @@ main (int argc, char **argv)
const char *sname = elf_strptr (elf, shdrstrndx, shdr->sh_name);
if (sname == NULL)
fail_elf_idx ("couldn't get section name", fname, scnnum);
- if ((scnstrents[scnnum] = ebl_strtabadd (strings, sname, 0)) == NULL)
- fail ("No memory to add to merged string table", NULL);
+ if ((scnstrents[scnnum] = dwelf_strtab_add (strings, sname)) == NULL)
+ fail ("No memory to add to merged string table", NULL);
}
if (layout)
@@ -295,7 +296,7 @@ main (int argc, char **argv)
if (symd == NULL)
fail_elf ("couldn't get symtab data", fname);
size_t symsnum = symd->d_size / elsize;
- symstrents = malloc (symsnum * sizeof (struct Ebl_Strent *));
+ symstrents = malloc (symsnum * sizeof (Dwelf_Strent *));
if (symstrents == NULL)
fail_errno ("Couldn't allocate memory for symbol strings", NULL);
for (size_t i = 0; i < symsnum; i++)
@@ -309,7 +310,7 @@ main (int argc, char **argv)
const char *sname = elf_strptr (elf, strtabndx, sym->st_name);
if (sname == NULL)
fail_elf_idx ("Couldn't get symbol name", fname, i);
- if ((symstrents[i] = ebl_strtabadd (strings, sname, 0)) == NULL)
+ if ((symstrents[i] = dwelf_strtab_add (strings, sname)) == NULL)
fail_idx ("No memory to add to merged string table symbol",
fname, i);
}
@@ -317,7 +318,7 @@ main (int argc, char **argv)
/* We got all strings, build the new string table and store it as
new strtab. */
- ebl_strtabfinalize (strings, &newstrtabdata);
+ dwelf_strtab_finalize (strings, &newstrtabdata);
/* We share at least the empty string so the result is at least 1
byte smaller. */
@@ -453,7 +454,7 @@ main (int argc, char **argv)
GElf_Shdr newshdr;
newshdr.sh_name = (shdr->sh_name != 0
- ? ebl_strtaboffset (scnstrents[ndx]) : 0);
+ ? dwelf_strent_off (scnstrents[ndx]) : 0);
newshdr.sh_type = shdr->sh_type;
newshdr.sh_flags = shdr->sh_flags;
newshdr.sh_addr = shdr->sh_addr;
@@ -528,7 +529,7 @@ main (int argc, char **argv)
sym.st_shndx = newsecndx (sym.st_shndx, "section", ndx,
"symbol", i);
if (update_name && sym.st_name != 0)
- sym.st_name = ebl_strtaboffset (symstrents[i]);
+ sym.st_name = dwelf_strent_off (symstrents[i]);
/* We explicitly don't update the SHNDX table at
the same time, we do that below. */
diff --git a/tests/update3.c b/tests/update3.c
index d760687a..7a4224dd 100644
--- a/tests/update3.c
+++ b/tests/update3.c
@@ -1,5 +1,5 @@
/* Test program for elf_update function.
- Copyright (C) 2000, 2002, 2005 Red Hat, Inc.
+ Copyright (C) 2000, 2002, 2005, 2016 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <[email protected]>, 2000.
@@ -28,7 +28,7 @@
#include <string.h>
#include <unistd.h>
-#include ELFUTILS_HEADER(ebl)
+#include ELFUTILS_HEADER(dwelf)
int
@@ -42,8 +42,8 @@ main (int argc, char *argv[] __attribute__ ((unused)))
Elf_Scn *scn;
Elf32_Shdr *shdr;
Elf_Data *data;
- struct Ebl_Strtab *shst;
- struct Ebl_Strent *shstrtabse;
+ Dwelf_Strtab *shst;
+ Dwelf_Strent *shstrtabse;
int i;
fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
@@ -107,7 +107,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
phdr[0].p_type = PT_PHDR;
elf_flagphdr (elf, ELF_C_SET, ELF_F_DIRTY);
- shst = ebl_strtabinit (true);
+ shst = dwelf_strtab_init (true);
scn = elf_newscn (elf);
if (scn == NULL)
@@ -122,7 +122,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
exit (1);
}
- shstrtabse = ebl_strtabadd (shst, ".shstrtab", 0);
+ shstrtabse = dwelf_strtab_add (shst, ".shstrtab");
shdr->sh_type = SHT_STRTAB;
shdr->sh_flags = 0;
@@ -143,9 +143,9 @@ main (int argc, char *argv[] __attribute__ ((unused)))
}
/* No more sections, finalize the section header string table. */
- ebl_strtabfinalize (shst, data);
+ dwelf_strtab_finalize (shst, data);
- shdr->sh_name = ebl_strtaboffset (shstrtabse);
+ shdr->sh_name = dwelf_strent_off (shstrtabse);
/* Let the library compute the internal structure information. */
if (elf_update (elf, ELF_C_NULL) < 0)
@@ -173,7 +173,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
}
/* We don't need the string table anymore. */
- ebl_strtabfree (shst);
+ dwelf_strtab_free (shst);
/* And the data allocated in the .shstrtab section. */
free (data->d_buf);
diff --git a/tests/update4.c b/tests/update4.c
index 85de6c35..a9bd4bf9 100644
--- a/tests/update4.c
+++ b/tests/update4.c
@@ -1,5 +1,5 @@
/* Test program for elf_update function.
- Copyright (C) 2000, 2001, 2002, 2005 Red Hat, Inc.
+ Copyright (C) 2000, 2001, 2002, 2005, 2016 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <[email protected]>, 2000.
@@ -28,7 +28,7 @@
#include <string.h>
#include <unistd.h>
-#include ELFUTILS_HEADER(ebl)
+#include ELFUTILS_HEADER(dwelf)
int
@@ -42,12 +42,12 @@ main (int argc, char *argv[] __attribute__ ((unused)))
Elf_Scn *scn;
Elf32_Shdr *shdr;
Elf_Data *data;
- struct Ebl_Strtab *shst;
- struct Ebl_Strent *firstse;
- struct Ebl_Strent *secondse;
- struct Ebl_Strent *thirdse;
- struct Ebl_Strent *fourthse;
- struct Ebl_Strent *shstrtabse;
+ Dwelf_Strtab *shst;
+ Dwelf_Strent *firstse;
+ Dwelf_Strent *secondse;
+ Dwelf_Strent *thirdse;
+ Dwelf_Strent *fourthse;
+ Dwelf_Strent *shstrtabse;
int i;
fd = open (fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
@@ -111,7 +111,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
phdr[0].p_type = PT_PHDR;
elf_flagphdr (elf, ELF_C_SET, ELF_F_DIRTY);
- shst = ebl_strtabinit (true);
+ shst = dwelf_strtab_init (true);
scn = elf_newscn (elf);
if (scn == NULL)
@@ -126,7 +126,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
exit (1);
}
- firstse = ebl_strtabadd (shst, ".first", 0);
+ firstse = dwelf_strtab_add (shst, ".first");
shdr->sh_type = SHT_PROGBITS;
shdr->sh_flags = SHF_ALLOC | SHF_EXECINSTR;
@@ -162,7 +162,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
exit (1);
}
- secondse = ebl_strtabadd (shst, ".second", 0);
+ secondse = dwelf_strtab_add (shst, ".second");
shdr->sh_type = SHT_PROGBITS;
shdr->sh_flags = SHF_ALLOC | SHF_WRITE;
@@ -198,7 +198,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
exit (1);
}
- thirdse = ebl_strtabadd (shst, ".third", 0);
+ thirdse = dwelf_strtab_add (shst, ".third");
shdr->sh_type = SHT_PROGBITS;
shdr->sh_flags = SHF_ALLOC | SHF_EXECINSTR;
@@ -234,7 +234,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
exit (1);
}
- fourthse = ebl_strtabadd (shst, ".fourth", 0);
+ fourthse = dwelf_strtab_add (shst, ".fourth");
shdr->sh_type = SHT_NOBITS;
shdr->sh_flags = SHF_ALLOC | SHF_EXECINSTR;
@@ -271,7 +271,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
exit (1);
}
- shstrtabse = ebl_strtabadd (shst, ".shstrtab", 0);
+ shstrtabse = dwelf_strtab_add (shst, ".shstrtab");
shdr->sh_type = SHT_STRTAB;
shdr->sh_flags = 0;
@@ -291,13 +291,13 @@ main (int argc, char *argv[] __attribute__ ((unused)))
}
/* No more sections, finalize the section header string table. */
- ebl_strtabfinalize (shst, data);
+ dwelf_strtab_finalize (shst, data);
- elf32_getshdr (elf_getscn (elf, 1))->sh_name = ebl_strtaboffset (firstse);
- elf32_getshdr (elf_getscn (elf, 2))->sh_name = ebl_strtaboffset (secondse);
- elf32_getshdr (elf_getscn (elf, 3))->sh_name = ebl_strtaboffset (thirdse);
- elf32_getshdr (elf_getscn (elf, 4))->sh_name = ebl_strtaboffset (fourthse);
- shdr->sh_name = ebl_strtaboffset (shstrtabse);
+ elf32_getshdr (elf_getscn (elf, 1))->sh_name = dwelf_strent_off (firstse);
+ elf32_getshdr (elf_getscn (elf, 2))->sh_name = dwelf_strent_off (secondse);
+ elf32_getshdr (elf_getscn (elf, 3))->sh_name = dwelf_strent_off (thirdse);
+ elf32_getshdr (elf_getscn (elf, 4))->sh_name = dwelf_strent_off (fourthse);
+ shdr->sh_name = dwelf_strent_off (shstrtabse);
/* Let the library compute the internal structure information. */
if (elf_update (elf, ELF_C_NULL) < 0)
@@ -325,7 +325,7 @@ main (int argc, char *argv[] __attribute__ ((unused)))
}
/* We don't need the string table anymore. */
- ebl_strtabfree (shst);
+ dwelf_strtab_free (shst);
/* And the data allocated in the .shstrtab section. */
free (data->d_buf);