diff options
author | Cary Coutant <ccoutant@google.com> | 2009-01-15 01:29:25 +0000 |
---|---|---|
committer | Cary Coutant <ccoutant@google.com> | 2009-01-15 01:29:25 +0000 |
commit | 0f7c0701ba26bd4c94e968f6be5c954819c97f81 (patch) | |
tree | 3ffcaaf955c71edad7e9d7b1965894a3e5e3d722 /gold/testsuite | |
parent | fa7f3e72292434483fbce576f8613a1af727df6c (diff) | |
download | gdb-0f7c0701ba26bd4c94e968f6be5c954819c97f81.zip gdb-0f7c0701ba26bd4c94e968f6be5c954819c97f81.tar.gz gdb-0f7c0701ba26bd4c94e968f6be5c954819c97f81.tar.bz2 |
* archive.cc (Archive::get_elf_object_for_member): Remove call
to File_read::claim_for_plugin.
* descriptors.cc (Descriptors::open): Remove reference to
is_claimed.
(Descriptors::claim_for_plugin): Remove.
* descriptors.h (Descriptors::claim_for_plugin): Remove.
(Descriptors::is_claimed): Remove.
(claim_descriptor_for_plugin): Remove.
* fileread.cc (File_read::claim_for_plugin): Remove.
* fileread.h (File_read::claim_for_plugin): Remove.
(File_read::descriptor): Reopen descriptor if necessary.
* plugin.cc (Plugin::load): Add two new APIs to transfer vector.
(Plugin_manager::all_symbols_read): Add task parameter. Change
all callers.
(Plugin_manager::get_input_file): New function.
(Plugin_manager::release_input_file): New function.
(Pluginobj::Pluginobj): Add filesize parameter and initialize
corresponding data member.
(Sized_pluginobj::Sized_pluginobj): Add filesize parameter
and pass to base constructor. Change all callers.
(get_input_file, release_input_file): New functions.
(make_sized_plugin_object): Add filesize parameter. Change all callers.
* plugin.h (Plugin_manager::Plugin_manager): Initialize task_ member.
(Plugin_manager::all_symbols_read): Add task parameter.
(Plugin_manager::get_input_file): New function.
(Plugin_manager::release_input_file): New function.
(Plugin_manager::task_): New data member.
(Pluginobj::Pluginobj): Add filesize parameter.
(Pluginobj::filename): New function.
(Pluginobj::descriptor): New function.
(Pluginobj::filesize): New function.
(Pluginobj::filesize_): New data member.
(Sized_pluginobj::Sized_pluginobj): Add filesize parameter.
* readsyms.cc (Read_symbols::do_read_symbols): Remove call to
File_read::claim_for_plugin; use Object::unlock to unlock the file.
* testsuite/Makefile.am (plugin_test_4): New test case for plugins
with archive libraries.
* testsuite/Makefile.in: Regenerate.
* testsuite/plugin_test.c (struct sym_info): New type.
(get_input_file, release_input_file): New static variables.
(onload): Capture new transfer vector entries.
(claim_file_hook): Stop reading at end of file according to filesize.
Factor out parsing of readelf output into separate function.
(all_symbols_read_hook): Exercise get_input_file and release_input_file
APIs and get the source file name from the symbol table. Convert
source file name to corresponding object file name. Print info
message when adding new input files.
(parse_readelf_line): New function.
* testsuite/plugin_test_1.sh: Add checks for new info messages.
* testsuite/plugin_test_2.sh: Likewise.
* testsuite/plugin_test_3.sh: Likewise.
* testsuite/plugin_test_4.sh: New test case.
Diffstat (limited to 'gold/testsuite')
-rw-r--r-- | gold/testsuite/Makefile.am | 12 | ||||
-rw-r--r-- | gold/testsuite/Makefile.in | 43 | ||||
-rw-r--r-- | gold/testsuite/plugin_test.c | 232 | ||||
-rwxr-xr-x | gold/testsuite/plugin_test_1.sh | 5 | ||||
-rwxr-xr-x | gold/testsuite/plugin_test_2.sh | 4 | ||||
-rwxr-xr-x | gold/testsuite/plugin_test_3.sh | 5 | ||||
-rwxr-xr-x | gold/testsuite/plugin_test_4.sh | 58 |
7 files changed, 281 insertions, 78 deletions
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 40daf1a..c318718 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -981,6 +981,18 @@ plugin_test_3: two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms t plugin_test_3.err: plugin_test_3 @touch plugin_test_3.err +check_PROGRAMS += plugin_test_4 +check_SCRIPTS += plugin_test_4.sh +check_DATA += plugin_test_4.err +MOSTLYCLEANFILES += plugin_test_4.err +plugin_test_4: two_file_test_main.o plugin_test_4.a gcctestdir/ld plugin_test.so + $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so",--plugin-opt,"_Z4f13iv" two_file_test_main.o -Wl,--whole-archive,plugin_test_4.a,--no-whole-archive 2>plugin_test_4.err +plugin_test_4.err: plugin_test_4 + @touch plugin_test_4.err + +plugin_test_4.a: two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms + $(TEST_AR) cr $@ $^ + plugin_test.so: plugin_test.o $(LINK) -Bgcctestdir/ -shared plugin_test.o plugin_test.o: plugin_test.c diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index a8644c1..c1ad9c3 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -293,19 +293,23 @@ check_PROGRAMS = object_unittest$(EXEEXT) binary_unittest$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_20 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_1 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_2 \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_3 +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_3 \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_4 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_21 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_1.sh \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_2.sh \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_3.sh +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_3.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_4.sh @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_22 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_1.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_2.err \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_3.err +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_3.err \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_4.err @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__append_23 = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_1.err \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_2.err \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_3.err +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_3.err \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_4.err subdir = testsuite DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -407,7 +411,8 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS) @GCC_TRUE@@NATIVE_LINKER_TRUE@ thin_archive_test_2$(EXEEXT) @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@am__EXEEXT_16 = plugin_test_1$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_2$(EXEEXT) \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_3$(EXEEXT) +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_3$(EXEEXT) \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ plugin_test_4$(EXEEXT) basic_pic_test_SOURCES = basic_pic_test.c basic_pic_test_OBJECTS = basic_pic_test.$(OBJEXT) basic_pic_test_LDADD = $(LDADD) @@ -582,6 +587,12 @@ plugin_test_3_LDADD = $(LDADD) plugin_test_3_DEPENDENCIES = libgoldtest.a ../libgold.a \ ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +plugin_test_4_SOURCES = plugin_test_4.c +plugin_test_4_OBJECTS = plugin_test_4.$(OBJEXT) +plugin_test_4_LDADD = $(LDADD) +plugin_test_4_DEPENDENCIES = libgoldtest.a ../libgold.a \ + ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) am__protected_1_SOURCES_DIST = protected_main_1.cc protected_main_2.cc \ protected_main_3.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@am_protected_1_OBJECTS = \ @@ -866,7 +877,7 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c \ $(initpri1_SOURCES) $(justsyms_SOURCES) many_sections_r_test.c \ $(many_sections_test_SOURCES) $(object_unittest_SOURCES) \ plugin_test_1.c plugin_test_2.c plugin_test_3.c \ - $(protected_1_SOURCES) $(protected_2_SOURCES) \ + plugin_test_4.c $(protected_1_SOURCES) $(protected_2_SOURCES) \ $(relro_script_test_SOURCES) $(relro_test_SOURCES) \ $(script_test_1_SOURCES) $(script_test_2_SOURCES) \ script_test_3.c $(thin_archive_test_1_SOURCES) \ @@ -918,7 +929,8 @@ DIST_SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c \ $(am__initpri1_SOURCES_DIST) $(am__justsyms_SOURCES_DIST) \ many_sections_r_test.c $(am__many_sections_test_SOURCES_DIST) \ $(object_unittest_SOURCES) plugin_test_1.c plugin_test_2.c \ - plugin_test_3.c $(am__protected_1_SOURCES_DIST) \ + plugin_test_3.c plugin_test_4.c \ + $(am__protected_1_SOURCES_DIST) \ $(am__protected_2_SOURCES_DIST) \ $(am__relro_script_test_SOURCES_DIST) \ $(am__relro_test_SOURCES_DIST) \ @@ -1637,6 +1649,15 @@ object_unittest$(EXEEXT): $(object_unittest_OBJECTS) $(object_unittest_DEPENDENC @PLUGINS_FALSE@plugin_test_3$(EXEEXT): $(plugin_test_3_OBJECTS) $(plugin_test_3_DEPENDENCIES) @PLUGINS_FALSE@ @rm -f plugin_test_3$(EXEEXT) @PLUGINS_FALSE@ $(LINK) $(plugin_test_3_LDFLAGS) $(plugin_test_3_OBJECTS) $(plugin_test_3_LDADD) $(LIBS) +@GCC_FALSE@plugin_test_4$(EXEEXT): $(plugin_test_4_OBJECTS) $(plugin_test_4_DEPENDENCIES) +@GCC_FALSE@ @rm -f plugin_test_4$(EXEEXT) +@GCC_FALSE@ $(LINK) $(plugin_test_4_LDFLAGS) $(plugin_test_4_OBJECTS) $(plugin_test_4_LDADD) $(LIBS) +@NATIVE_LINKER_FALSE@plugin_test_4$(EXEEXT): $(plugin_test_4_OBJECTS) $(plugin_test_4_DEPENDENCIES) +@NATIVE_LINKER_FALSE@ @rm -f plugin_test_4$(EXEEXT) +@NATIVE_LINKER_FALSE@ $(LINK) $(plugin_test_4_LDFLAGS) $(plugin_test_4_OBJECTS) $(plugin_test_4_LDADD) $(LIBS) +@PLUGINS_FALSE@plugin_test_4$(EXEEXT): $(plugin_test_4_OBJECTS) $(plugin_test_4_DEPENDENCIES) +@PLUGINS_FALSE@ @rm -f plugin_test_4$(EXEEXT) +@PLUGINS_FALSE@ $(LINK) $(plugin_test_4_LDFLAGS) $(plugin_test_4_OBJECTS) $(plugin_test_4_LDADD) $(LIBS) protected_1$(EXEEXT): $(protected_1_OBJECTS) $(protected_1_DEPENDENCIES) @rm -f protected_1$(EXEEXT) $(CXXLINK) $(protected_1_LDFLAGS) $(protected_1_OBJECTS) $(protected_1_LDADD) $(LIBS) @@ -1823,6 +1844,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_2.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_3.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin_test_4.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_3.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_main_1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_main_2.Po@am__quote@ @@ -2487,6 +2509,13 @@ uninstall-am: uninstall-info-am @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--export-dynamic -Wl,--no-demangle,--plugin,"./plugin_test.so",--plugin-opt,"_Z4f13iv" two_file_test_main.o two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms empty.syms 2>plugin_test_3.err @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_3.err: plugin_test_3 @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ @touch plugin_test_3.err +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_4: two_file_test_main.o plugin_test_4.a gcctestdir/ld plugin_test.so +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--no-demangle,--plugin,"./plugin_test.so",--plugin-opt,"_Z4f13iv" two_file_test_main.o -Wl,--whole-archive,plugin_test_4.a,--no-whole-archive 2>plugin_test_4.err +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_4.err: plugin_test_4 +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ @touch plugin_test_4.err + +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test_4.a: two_file_test_1.syms two_file_test_1b.syms two_file_test_2.syms +@GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(TEST_AR) cr $@ $^ @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@plugin_test.so: plugin_test.o @GCC_TRUE@@NATIVE_LINKER_TRUE@@PLUGINS_TRUE@ $(LINK) -Bgcctestdir/ -shared plugin_test.o diff --git a/gold/testsuite/plugin_test.c b/gold/testsuite/plugin_test.c index c36fee4..2218d08 100644 --- a/gold/testsuite/plugin_test.c +++ b/gold/testsuite/plugin_test.c @@ -1,6 +1,6 @@ /* test_plugin.c -- simple linker plugin test - Copyright 2008 Free Software Foundation, Inc. + Copyright 2008, 2009 Free Software Foundation, Inc. Written by Cary Coutant <ccoutant@google.com>. This file is part of gold. @@ -34,6 +34,16 @@ struct claimed_file struct claimed_file* next; }; +struct sym_info +{ + int size; + char* type; + char* bind; + char* vis; + char* sect; + char* name; +}; + static struct claimed_file* first_claimed_file = NULL; static struct claimed_file* last_claimed_file = NULL; @@ -44,6 +54,8 @@ static ld_plugin_add_symbols add_symbols = NULL; static ld_plugin_get_symbols get_symbols = NULL; static ld_plugin_add_input_file add_input_file = NULL; static ld_plugin_message message = NULL; +static ld_plugin_get_input_file get_input_file = NULL; +static ld_plugin_release_input_file release_input_file = NULL; #define MAXOPTS 10 @@ -56,6 +68,8 @@ enum ld_plugin_status claim_file_hook(const struct ld_plugin_input_file *file, enum ld_plugin_status all_symbols_read_hook(void); enum ld_plugin_status cleanup_hook(void); +static void parse_readelf_line(char*, struct sym_info*); + enum ld_plugin_status onload(struct ld_plugin_tv *tv) { @@ -102,6 +116,12 @@ onload(struct ld_plugin_tv *tv) case LDPT_MESSAGE: message = entry->tv_u.tv_message; break; + case LDPT_GET_INPUT_FILE: + get_input_file = entry->tv_u.tv_get_input_file; + break; + case LDPT_RELEASE_INPUT_FILE: + release_input_file = entry->tv_u.tv_release_input_file; + break; default: break; } @@ -162,21 +182,17 @@ enum ld_plugin_status claim_file_hook (const struct ld_plugin_input_file* file, int* claimed) { int len; + off_t end_offset; char buf[160]; struct claimed_file* claimed_file; struct ld_plugin_symbol* syms; int nsyms = 0; int maxsyms = 0; FILE* irfile; - char *p; - char *pbind; - char *pvis; - char *psect; + struct sym_info info; int weak; int def; int vis; - int size; - char* name; int is_comdat; int i; @@ -187,6 +203,7 @@ claim_file_hook (const struct ld_plugin_input_file* file, int* claimed) /* Look for the beginning of output from readelf -s. */ irfile = fdopen(file->fd, "r"); (void)fseek(irfile, file->offset, SEEK_SET); + end_offset = file->offset + file->filesize; len = fread(buf, 1, 13, irfile); if (len < 13 || strncmp(buf, "\nSymbol table", 13) != 0) return LDPS_OK; @@ -207,68 +224,28 @@ claim_file_hook (const struct ld_plugin_input_file* file, int* claimed) if (syms == NULL) return LDPS_ERR; maxsyms = 8; - while (fgets(buf, sizeof(buf), irfile) != NULL) + while (ftell(irfile) < end_offset + && fgets(buf, sizeof(buf), irfile) != NULL) { - p = buf; - p += strspn(p, " "); - - /* Index field. */ - p += strcspn(p, " "); - p += strspn(p, " "); - - /* Value field. */ - p += strcspn(p, " "); - p += strspn(p, " "); - - /* Size field. */ - size = atoi(p); - p += strcspn(p, " "); - p += strspn(p, " "); - - /* Type field. */ - p += strcspn(p, " "); - p += strspn(p, " "); - - /* Binding field. */ - pbind = p; - p += strcspn(p, " "); - p += strspn(p, " "); - - /* Visibility field. */ - pvis = p; - p += strcspn(p, " "); - p += strspn(p, " "); - - /* Section field. */ - psect = p; - p += strcspn(p, " "); - p += strspn(p, " "); - - /* Name field. */ - /* FIXME: Look for version. */ - len = strlen(p); - if (p[len-1] == '\n') - p[--len] = '\0'; - name = malloc(len + 1); - strncpy(name, p, len + 1); + parse_readelf_line(buf, &info); /* Ignore local symbols. */ - if (strncmp(pbind, "LOCAL", 5) == 0) + if (strncmp(info.bind, "LOCAL", 5) == 0) continue; - weak = strncmp(pbind, "WEAK", 4) == 0; - if (strncmp(psect, "UND", 3) == 0) + weak = strncmp(info.bind, "WEAK", 4) == 0; + if (strncmp(info.sect, "UND", 3) == 0) def = weak ? LDPK_WEAKUNDEF : LDPK_UNDEF; - else if (strncmp(psect, "COM", 3) == 0) + else if (strncmp(info.sect, "COM", 3) == 0) def = LDPK_COMMON; else def = weak ? LDPK_WEAKDEF : LDPK_DEF; - if (strncmp(pvis, "INTERNAL", 8) == 0) + if (strncmp(info.vis, "INTERNAL", 8) == 0) vis = LDPV_INTERNAL; - else if (strncmp(pvis, "HIDDEN", 6) == 0) + else if (strncmp(info.vis, "HIDDEN", 6) == 0) vis = LDPV_HIDDEN; - else if (strncmp(pvis, "PROTECTED", 9) == 0) + else if (strncmp(info.vis, "PROTECTED", 9) == 0) vis = LDPV_PROTECTED; else vis = LDPV_DEFAULT; @@ -278,7 +255,7 @@ claim_file_hook (const struct ld_plugin_input_file* file, int* claimed) is_comdat = 0; for (i = 0; i < nopts; ++i) { - if (name != NULL && strcmp(name, opts[i]) == 0) + if (info.name != NULL && strcmp(info.name, opts[i]) == 0) { is_comdat = 1; break; @@ -294,12 +271,19 @@ claim_file_hook (const struct ld_plugin_input_file* file, int* claimed) maxsyms *= 2; } - syms[nsyms].name = name; + if (info.name == NULL) + syms[nsyms].name = NULL; + else + { + len = strlen(info.name); + syms[nsyms].name = malloc(len + 1); + strncpy(syms[nsyms].name, info.name, len + 1); + } syms[nsyms].version = NULL; syms[nsyms].def = def; syms[nsyms].visibility = vis; - syms[nsyms].size = size; - syms[nsyms].comdat_key = is_comdat ? name : NULL; + syms[nsyms].size = info.size; + syms[nsyms].comdat_key = is_comdat ? syms[nsyms].name : NULL; syms[nsyms].resolution = LDPR_UNKNOWN; ++nsyms; } @@ -335,8 +319,14 @@ all_symbols_read_hook(void) int i; const char* res; struct claimed_file* claimed_file; + struct ld_plugin_input_file file; + FILE* irfile; + off_t end_offset; + struct sym_info info; + int len; char buf[160]; - char *p; + char* p; + const char* filename; (*message)(LDPL_INFO, "all symbols read hook called"); @@ -352,6 +342,7 @@ all_symbols_read_hook(void) { (*get_symbols)(claimed_file->handle, claimed_file->nsyms, claimed_file->syms); + for (i = 0; i < claimed_file->nsyms; ++i) { switch (claimed_file->syms[i].resolution) @@ -397,28 +388,83 @@ all_symbols_read_hook(void) fprintf(stderr, "tv_add_input_file interface missing\n"); return LDPS_ERR; } + if (get_input_file == NULL) + { + fprintf(stderr, "tv_get_input_file interface missing\n"); + return LDPS_ERR; + } + if (release_input_file == NULL) + { + fprintf(stderr, "tv_release_input_file interface missing\n"); + return LDPS_ERR; + } for (claimed_file = first_claimed_file; claimed_file != NULL; claimed_file = claimed_file->next) { + (*get_input_file) (claimed_file->handle, &file); + + /* Look for the beginning of output from readelf -s. */ + irfile = fdopen(file.fd, "r"); + (void)fseek(irfile, file.offset, SEEK_SET); + end_offset = file.offset + file.filesize; + len = fread(buf, 1, 13, irfile); + if (len < 13 || strncmp(buf, "\nSymbol table", 13) != 0) + { + fprintf(stderr, "%s: can't re-read original input file\n", + claimed_file->name); + return LDPS_ERR; + } + + /* Skip the two header lines. */ + (void) fgets(buf, sizeof(buf), irfile); + (void) fgets(buf, sizeof(buf), irfile); + + filename = NULL; + while (ftell(irfile) < end_offset + && fgets(buf, sizeof(buf), irfile) != NULL) + { + parse_readelf_line(buf, &info); + + /* Look for file name. */ + if (strncmp(info.type, "FILE", 4) == 0) + { + len = strlen(info.name); + p = malloc(len + 1); + strncpy(p, info.name, len + 1); + filename = p; + break; + } + } + + (*release_input_file) (claimed_file->handle); + + if (filename == NULL) + filename = claimed_file->name; + if (claimed_file->nsyms == 0) continue; - if (strlen(claimed_file->name) >= sizeof(buf)) + + if (strlen(filename) >= sizeof(buf)) { - (*message)(LDPL_FATAL, "%s: filename too long", claimed_file->name); + (*message)(LDPL_FATAL, "%s: filename too long", filename); return LDPS_ERR; } - strcpy(buf, claimed_file->name); + strcpy(buf, filename); p = strrchr(buf, '.'); - if (p == NULL || strcmp(p, ".syms") != 0) + if (p == NULL + || (strcmp(p, ".syms") != 0 + && strcmp(p, ".c") != 0 + && strcmp(p, ".cc") != 0)) { - (*message)(LDPL_FATAL, "%s: filename must have '.syms' suffix", - claimed_file->name); + (*message)(LDPL_FATAL, "%s: filename has unknown suffix", + filename); return LDPS_ERR; } p[1] = 'o'; p[2] = '\0'; + (*message)(LDPL_INFO, "%s: adding new input file", buf); (*add_input_file)(buf); } @@ -431,3 +477,53 @@ cleanup_hook(void) (*message)(LDPL_INFO, "cleanup hook called"); return LDPS_OK; } + +static void +parse_readelf_line(char* p, struct sym_info* info) +{ + int len; + + p += strspn(p, " "); + + /* Index field. */ + p += strcspn(p, " "); + p += strspn(p, " "); + + /* Value field. */ + p += strcspn(p, " "); + p += strspn(p, " "); + + /* Size field. */ + info->size = atoi(p); + p += strcspn(p, " "); + p += strspn(p, " "); + + /* Type field. */ + info->type = p; + p += strcspn(p, " "); + p += strspn(p, " "); + + /* Binding field. */ + info->bind = p; + p += strcspn(p, " "); + p += strspn(p, " "); + + /* Visibility field. */ + info->vis = p; + p += strcspn(p, " "); + p += strspn(p, " "); + + /* Section field. */ + info->sect = p; + p += strcspn(p, " "); + p += strspn(p, " "); + + /* Name field. */ + /* FIXME: Look for version. */ + len = strlen(p); + if (len == 0) + p = NULL; + else if (p[len-1] == '\n') + p[--len] = '\0'; + info->name = p; +} diff --git a/gold/testsuite/plugin_test_1.sh b/gold/testsuite/plugin_test_1.sh index 5e16139..4d3ed41 100755 --- a/gold/testsuite/plugin_test_1.sh +++ b/gold/testsuite/plugin_test_1.sh @@ -2,7 +2,7 @@ # plugin_test_1.sh -- a test case for the plugin API. -# Copyright 2008 Free Software Foundation, Inc. +# Copyright 2008, 2009 Free Software Foundation, Inc. # Written by Cary Coutant <ccoutant@google.com>. # This file is part of gold. @@ -51,6 +51,9 @@ check plugin_test_1.err "two_file_test_1.syms: _Z2t2v: PREVAILING_DEF_REG" check plugin_test_1.err "two_file_test_1.syms: v2: RESOLVED_IR" check plugin_test_1.err "two_file_test_1.syms: t17data: RESOLVED_IR" check plugin_test_1.err "two_file_test_2.syms: _Z4f13iv: PREEMPTED_IR" +check plugin_test_1.err "two_file_test_1.o: adding new input file" +check plugin_test_1.err "two_file_test_1b.o: adding new input file" +check plugin_test_1.err "two_file_test_2.o: adding new input file" check plugin_test_1.err "cleanup hook called" exit 0 diff --git a/gold/testsuite/plugin_test_2.sh b/gold/testsuite/plugin_test_2.sh index 41865ac..a47d22a 100755 --- a/gold/testsuite/plugin_test_2.sh +++ b/gold/testsuite/plugin_test_2.sh @@ -2,7 +2,7 @@ # plugin_test_2.sh -- a test case for the plugin API. -# Copyright 2008 Free Software Foundation, Inc. +# Copyright 2008, 2009 Free Software Foundation, Inc. # Written by Cary Coutant <ccoutant@google.com>. # This file is part of gold. @@ -49,6 +49,8 @@ check plugin_test_2.err "two_file_test_1.syms: _Z4f13iv: PREVAILING_DEF_REG" check plugin_test_2.err "two_file_test_1.syms: _Z2t2v: PREVAILING_DEF_REG" check plugin_test_2.err "two_file_test_1.syms: v2: RESOLVED_DYN" check plugin_test_2.err "two_file_test_1.syms: t17data: RESOLVED_DYN" +check plugin_test_2.err "two_file_test_1.o: adding new input file" +check plugin_test_2.err "two_file_test_1b.o: adding new input file" check plugin_test_2.err "cleanup hook called" exit 0 diff --git a/gold/testsuite/plugin_test_3.sh b/gold/testsuite/plugin_test_3.sh index 837595f..961df15 100755 --- a/gold/testsuite/plugin_test_3.sh +++ b/gold/testsuite/plugin_test_3.sh @@ -2,7 +2,7 @@ # plugin_test_3.sh -- a test case for the plugin API. -# Copyright 2008 Free Software Foundation, Inc. +# Copyright 2008, 2009 Free Software Foundation, Inc. # Written by Cary Coutant <ccoutant@google.com>. # This file is part of gold. @@ -51,6 +51,9 @@ check plugin_test_3.err "two_file_test_1.syms: _Z2t2v: PREVAILING_DEF_REG" check plugin_test_3.err "two_file_test_1.syms: v2: RESOLVED_IR" check plugin_test_3.err "two_file_test_1.syms: t17data: RESOLVED_IR" check plugin_test_3.err "two_file_test_2.syms: _Z4f13iv: PREEMPTED_IR" +check plugin_test_3.err "two_file_test_1.o: adding new input file" +check plugin_test_3.err "two_file_test_1b.o: adding new input file" +check plugin_test_3.err "two_file_test_2.o: adding new input file" check plugin_test_3.err "cleanup hook called" exit 0 diff --git a/gold/testsuite/plugin_test_4.sh b/gold/testsuite/plugin_test_4.sh new file mode 100755 index 0000000..89df46c --- /dev/null +++ b/gold/testsuite/plugin_test_4.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# plugin_test_4.sh -- a test case for the plugin API. + +# Copyright 2009 Free Software Foundation, Inc. +# Written by Cary Coutant <ccoutant@google.com>. + +# This file is part of gold. + +# 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. + +# This file goes with plugin_test_4.c, a simple plug-in library that +# exercises the basic interfaces and prints out version numbers and +# options passed to the plugin. + +check() +{ + if ! grep -q "$2" "$1" + then + echo "Did not find expected output in $1:" + echo " $2" + echo "" + echo "Actual output below:" + cat "$1" + exit 1 + fi +} + +check plugin_test_4.err "API version:" +check plugin_test_4.err "gold version:" +check plugin_test_4.err "option: _Z4f13iv" +check plugin_test_4.err "two_file_test_main.o: claim file hook called" +check plugin_test_4.err "plugin_test_4.a: claim file hook called" +check plugin_test_4.err "plugin_test_4.a: claiming file" +check plugin_test_4.err "plugin_test_4.a: _Z4f13iv: PREVAILING_DEF_IRONLY" +check plugin_test_4.err "plugin_test_4.a: _Z2t2v: PREVAILING_DEF_REG" +check plugin_test_4.err "plugin_test_4.a: v2: RESOLVED_IR" +check plugin_test_4.err "plugin_test_4.a: t17data: RESOLVED_IR" +check plugin_test_4.err "plugin_test_4.a: _Z4f13iv: PREEMPTED_IR" +check plugin_test_4.err "two_file_test_1.o: adding new input file" +check plugin_test_4.err "two_file_test_1b.o: adding new input file" +check plugin_test_4.err "two_file_test_2.o: adding new input file" +check plugin_test_4.err "cleanup hook called" + +exit 0 |