public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gold: Fix a minor bug in --exclude-libs.
@ 2009-05-20  1:26 Doug Kwan (關振德)
  2009-05-20  5:49 ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Doug Kwan (關振德) @ 2009-05-20  1:26 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 1032 bytes --]

This fixes a minor issue where directories in an archive name is not
stripped before matching for excluded libraries.  The fix was to call
lbasename to remove directories in a name like the GNU ld does.  The
test case is also updated.   This was tested on
x86_64-unknown-linux-gnu.

-Doug

2009-05-19  Doug Kwan  <dougkwan@google.com>

	* options.cc (General_options::check_excluded_libs): Strip
	off directories in archive name before matching like GNU ld does.
	* testsuite/Makefile.am (MOSTLYCLEANFILES,
	exclude_libs_test_DEPENDENCIES): Add alt/libexclude_libs_test_3.a
	(exclude_libs_test_LDFLAGS): Add linker option
	-Wl,--exclude-libs,libexclude_libs_test_3
	(exclude_libs_test_LADD): Add alt/libexclude_libs_test_3.a as
	an explicit archive without using -l.
	(alt/libexclude_libs_test_3.a): New make rule.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/exclude_libs_test.c : Declare lib3_default().
	(main): Call it.
	* exclude_libs_test.sh: Add tests for alt/exclude_libs_test_3.a.
	* exclude_libs_test_3.c: New file.

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 7356 bytes --]

diff -Nrup gold-cvs-4/src/gold/options.cc gold-cvs-2/src/gold/options.cc
--- gold-cvs-4/src/gold/options.cc	2009-05-19 18:08:30.571704000 -0700
+++ gold-cvs-2/src/gold/options.cc	2009-05-19 18:06:59.318688000 -0700
@@ -444,18 +444,21 @@ General_options::check_excluded_libs (co
   if (p != excluded_libs_.end())
     return true;
 
+  // First strip off any directories in name.
+  const char *basename = lbasename(name.c_str());
+
   // Try finding an exact match.
-  p = excluded_libs_.find(name);
+  p = excluded_libs_.find(std::string(basename));
   if (p != excluded_libs_.end())
     return true;
 
   // Try matching NAME without ".a" at the end.
-  size_t length = name.length();
+  size_t length = strlen(basename);
   if ((length >= 2)
-      && (name[length-2] == '.')
-      && (name[length-1] == 'a'))
+      && (basename[length - 2] == '.')
+      && (basename[length - 1] == 'a'))
     {
-      p = excluded_libs_.find(name.substr(0, length - 2));
+      p = excluded_libs_.find(std::string(basename, length - 2));
       if (p != excluded_libs_.end())
 	return true;
     }
diff -Nrup gold-cvs-4/src/gold/testsuite/Makefile.am gold-cvs-2/src/gold/testsuite/Makefile.am
--- gold-cvs-4/src/gold/testsuite/Makefile.am	2009-05-19 18:08:30.643625000 -0700
+++ gold-cvs-2/src/gold/testsuite/Makefile.am	2009-05-19 18:02:46.854589000 -0700
@@ -1042,19 +1042,23 @@ check_PROGRAMS += exclude_libs_test
 check_SCRIPTS += exclude_libs_test.sh
 check_DATA += exclude_libs_test.syms
 MOSTLYCLEANFILES += exclude_libs_test.syms libexclude_libs_test_1.a \
-        libexclude_libs_test_2.a
+        libexclude_libs_test_2.a alt/libexclude_libs_test_3.a
 exclude_libs_test_SOURCES = exclude_libs_test.c
 exclude_libs_test_DEPENDENCIES = gcctestdir/ld libexclude_libs_test_1.a \
-	libexclude_libs_test_2.a
-exclude_libs_test_LDFLAGS = -Bgcctestdir/ -L. \
-	-Wl,--exclude-libs,dummy:libexclude_libs_test_1
-exclude_libs_test_LDADD = -lexclude_libs_test_1 -lexclude_libs_test_2
+	libexclude_libs_test_2.a alt/libexclude_libs_test_3.a
+exclude_libs_test_LDFLAGS = -Bgcctestdir/ -L. -Lalt \
+	-Wl,--exclude-libs,dummy:libexclude_libs_test_1 \
+	-Wl,--exclude-libs,libexclude_libs_test_3
+exclude_libs_test_LDADD = -lexclude_libs_test_1 -lexclude_libs_test_2 \
+	alt/libexclude_libs_test_3.a
 exclude_libs_test.syms: exclude_libs_test
 	$(TEST_READELF) -sW $< >$@ 2>/dev/null
 libexclude_libs_test_1.a: exclude_libs_test_1.o
 	$(TEST_AR) rc $@ $^
 libexclude_libs_test_2.a: exclude_libs_test_2.o
 	$(TEST_AR) rc $@ $^
+alt/libexclude_libs_test_3.a: exclude_libs_test_3.o
+	$(TEST_AR) rc $@ $^
 
 endif GCC
 endif NATIVE_LINKER
diff -Nrup gold-cvs-4/src/gold/testsuite/Makefile.in gold-cvs-2/src/gold/testsuite/Makefile.in
--- gold-cvs-4/src/gold/testsuite/Makefile.in	2009-05-19 18:08:30.661613000 -0700
+++ gold-cvs-2/src/gold/testsuite/Makefile.in	2009-05-19 18:02:48.742325000 -0700
@@ -321,10 +321,8 @@ check_PROGRAMS = object_unittest$(EXEEXT
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_25 = exclude_libs_test.sh
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_26 = exclude_libs_test.syms
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_27 = exclude_libs_test.syms libexclude_libs_test_1.a \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@        libexclude_libs_test_2.a
+@GCC_TRUE@@NATIVE_LINKER_TRUE@        libexclude_libs_test_2.a alt/libexclude_libs_test_3.a
 
-@GCC_FALSE@exclude_libs_test_DEPENDENCIES =
-@NATIVE_LINKER_FALSE@exclude_libs_test_DEPENDENCIES =
 subdir = testsuite
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -1510,12 +1508,15 @@ binary_unittest_SOURCES = binary_unittes
 @GCC_TRUE@@NATIVE_LINKER_TRUE@thin_archive_test_2_LDADD = -lthinall
 @GCC_TRUE@@NATIVE_LINKER_TRUE@exclude_libs_test_SOURCES = exclude_libs_test.c
 @GCC_TRUE@@NATIVE_LINKER_TRUE@exclude_libs_test_DEPENDENCIES = gcctestdir/ld libexclude_libs_test_1.a \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@	libexclude_libs_test_2.a
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	libexclude_libs_test_2.a alt/libexclude_libs_test_3.a
 
-@GCC_TRUE@@NATIVE_LINKER_TRUE@exclude_libs_test_LDFLAGS = -Bgcctestdir/ -L. \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@	-Wl,--exclude-libs,dummy:libexclude_libs_test_1
+@GCC_TRUE@@NATIVE_LINKER_TRUE@exclude_libs_test_LDFLAGS = -Bgcctestdir/ -L. -Lalt \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	-Wl,--exclude-libs,dummy:libexclude_libs_test_1 \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	-Wl,--exclude-libs,libexclude_libs_test_3
+
+@GCC_TRUE@@NATIVE_LINKER_TRUE@exclude_libs_test_LDADD = -lexclude_libs_test_1 -lexclude_libs_test_2 \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	alt/libexclude_libs_test_3.a
 
-@GCC_TRUE@@NATIVE_LINKER_TRUE@exclude_libs_test_LDADD = -lexclude_libs_test_1 -lexclude_libs_test_2
 all: $(BUILT_SOURCES)
 	$(MAKE) $(AM_MAKEFLAGS) all-am
 
@@ -2599,6 +2600,8 @@ uninstall-am: uninstall-info-am
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	$(TEST_AR) rc $@ $^
 @GCC_TRUE@@NATIVE_LINKER_TRUE@libexclude_libs_test_2.a: exclude_libs_test_2.o
 @GCC_TRUE@@NATIVE_LINKER_TRUE@	$(TEST_AR) rc $@ $^
+@GCC_TRUE@@NATIVE_LINKER_TRUE@alt/libexclude_libs_test_3.a: exclude_libs_test_3.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@	$(TEST_AR) rc $@ $^
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
diff -Nrup gold-cvs-4/src/gold/testsuite/exclude_libs_test.c gold-cvs-2/src/gold/testsuite/exclude_libs_test.c
--- gold-cvs-4/src/gold/testsuite/exclude_libs_test.c	2009-05-19 15:14:17.000000000 -0700
+++ gold-cvs-2/src/gold/testsuite/exclude_libs_test.c	2009-05-19 17:47:29.566946000 -0700
@@ -1,5 +1,6 @@
 extern void lib1_default (void);
 extern void lib2_default (void);
+extern void lib3_default (void);
 
 int
 main (int argc __attribute__ ((unused)),
@@ -7,6 +8,7 @@ main (int argc __attribute__ ((unused)),
 {
   lib1_default ();
   lib2_default ();
+  lib3_default ();
   return 0;
 }
 
diff -Nrup gold-cvs-4/src/gold/testsuite/exclude_libs_test.sh gold-cvs-2/src/gold/testsuite/exclude_libs_test.sh
--- gold-cvs-4/src/gold/testsuite/exclude_libs_test.sh	2009-05-19 15:14:17.000000000 -0700
+++ gold-cvs-2/src/gold/testsuite/exclude_libs_test.sh	2009-05-19 17:48:23.009595000 -0700
@@ -55,5 +55,9 @@ check "exclude_libs_test.syms" "lib2_def
 check "exclude_libs_test.syms" "lib2_protected" "PROTECTED"
 check "exclude_libs_test.syms" "lib2_internal" "INTERNAL"
 check "exclude_libs_test.syms" "lib2_hidden" "HIDDEN"
+check "exclude_libs_test.syms" "lib3_default" "HIDDEN"
+check "exclude_libs_test.syms" "lib3_protected" "HIDDEN"
+check "exclude_libs_test.syms" "lib3_internal" "INTERNAL"
+check "exclude_libs_test.syms" "lib3_hidden" "HIDDEN"
 
 exit 0
diff -Nrup gold-cvs-4/src/gold/testsuite/exclude_libs_test_3.c gold-cvs-2/src/gold/testsuite/exclude_libs_test_3.c
--- gold-cvs-4/src/gold/testsuite/exclude_libs_test_3.c	1969-12-31 16:00:00.000000000 -0800
+++ gold-cvs-2/src/gold/testsuite/exclude_libs_test_3.c	2009-05-19 17:47:18.414590000 -0700
@@ -0,0 +1,24 @@
+void lib3_default (void);
+void lib3_hidden (void);
+void lib3_internal (void);
+void lib3_protected (void);
+
+void __attribute__((visibility ("default")))
+lib3_default (void)
+{
+}
+
+void __attribute__((visibility ("hidden")))
+lib3_hidden (void)
+{
+}
+
+void __attribute__((visibility ("internal")))
+lib3_internal (void)
+{
+}
+
+void __attribute__((visibility ("protected")))
+lib3_protected (void)
+{
+}

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-05-26 22:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-20  1:26 [PATCH] gold: Fix a minor bug in --exclude-libs Doug Kwan (關振德)
2009-05-20  5:49 ` Ian Lance Taylor
2009-05-20  6:15   ` Doug Kwan (關振德)
2009-05-20  6:27     ` Ian Lance Taylor
2009-05-20  6:49       ` Doug Kwan (關振德)
2009-05-26 22:55         ` Doug Kwan (關振德)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).