This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix some ldgram.y version script bugs


Hi!

The attached testcase shows a few bugs in symbol version script parsing.
One is that
VER {
  global: foo; bar; extern "C" { baz; };
  local: *;
};
is treated as if it was just:
VER {
  global: extern "C" { baz; };
  local: *;
};
(i.e. foo; bar; part is lost).
The second is that in order to export global or local symbols,
[g]lobal or similar hacks need to be used, but there is really no
need for such hacks, global or local should be treated as keywords
IMHO only when followed by semicolon.  For completeness the patch
handles extern identifier as well (again, shouldn't be ambiguous
in the grammer, extern as identifier can be only followed by
semicolon or }, while extern NAME { needs { after the NAME
and NAME is neither semicolon, nor }.

Ok to commit?

2005-08-16  Jakub Jelinek  <jakub@redhat.com>

	* ldgram.y (vers_defns): Don't loose pattern list before
	extern NAME {}.  Handle global, local and extern symbol names.
ld/testsuite/
	* ld-elfvers/vers.exp: Add a new test, vers30.
	* ld-elfvers/vers30.c: New file.
	* ld-elfvers/vers30.map: New file.
	* ld-elfvers/vers30.ver: New file.
	* ld-elfvers/vers30.dsym: New file.

--- ld/ldgram.y.jj	2005-08-16 11:21:45.000000000 +0200
+++ ld/ldgram.y	2005-08-16 15:12:47.000000000 +0200
@@ -1226,6 +1226,9 @@ vers_defns:
 			}
 		vers_defns opt_semicolon '}'
 			{
+			  struct bfd_elf_version_expr *pat;
+			  for (pat = $7; pat->next != NULL; pat = pat->next);
+			  pat->next = $1;
 			  $$ = $7;
 			  ldgram_vers_current_lang = $<name>6;
 			}
@@ -1239,6 +1242,30 @@ vers_defns:
 			  $$ = $5;
 			  ldgram_vers_current_lang = $<name>4;
 			}
+	|	GLOBAL
+		{
+		  $$ = lang_new_vers_pattern (NULL, "global", ldgram_vers_current_lang);
+		}
+	|	vers_defns ';' GLOBAL
+		{
+		  $$ = lang_new_vers_pattern ($1, "global", ldgram_vers_current_lang);
+		}
+	|	LOCAL
+		{
+		  $$ = lang_new_vers_pattern (NULL, "local", ldgram_vers_current_lang);
+		}
+	|	vers_defns ';' LOCAL
+		{
+		  $$ = lang_new_vers_pattern ($1, "local", ldgram_vers_current_lang);
+		}
+	|	EXTERN
+		{
+		  $$ = lang_new_vers_pattern (NULL, "extern", ldgram_vers_current_lang);
+		}
+	|	vers_defns ';' EXTERN
+		{
+		  $$ = lang_new_vers_pattern ($1, "extern", ldgram_vers_current_lang);
+		}
 	;
 
 opt_semicolon:
--- ld/testsuite/ld-elfvers/vers.exp.jj	2005-05-13 23:44:38.000000000 +0200
+++ ld/testsuite/ld-elfvers/vers.exp	2005-08-16 15:49:48.000000000 +0200
@@ -960,3 +960,7 @@ build_vers_lib_pic "vers28a" vers28a.c v
 build_vers_lib_pic "vers28b" vers28b.c vers28b "" vers28b.map vers28b.ver vers28b.dsym ""
 build_vers_lib_pic "vers28c" vers28c.c vers28c "vers28b.so vers28a.so" "" vers28c.ver vers28c.dsym ""
 build_vers_lib_pic_flags "vers29" vers29.c vers29 "" "" vers29.ver vers29.dsym "" "--default-symver"
+
+# Test #30 - test handling of symbol names global, local and extern in the
+# version script.
+build_vers_lib_pic "vers30" vers30.c vers30 "" vers30.map vers30.ver vers30.dsym ""
--- ld/testsuite/ld-elfvers/vers30.c.jj	2005-08-16 15:17:36.000000000 +0200
+++ ld/testsuite/ld-elfvers/vers30.c	2005-08-16 15:00:05.000000000 +0200
@@ -0,0 +1,7 @@
+void global (void) {}
+void local (void) {}
+void foo (void) {}
+void bar (void) {}
+void info (void) {}
+void baz (void) __asm ("extern");
+void baz (void) {}
--- ld/testsuite/ld-elfvers/vers30.map.jj	2005-08-16 15:17:36.000000000 +0200
+++ ld/testsuite/ld-elfvers/vers30.map	2005-08-16 15:17:23.000000000 +0200
@@ -0,0 +1,6 @@
+VERS_30.0 {
+  global:
+    foo; info; global; extern "C" { extern; };
+  local:
+    local; bar; *;
+};
--- ld/testsuite/ld-elfvers/vers30.ver.jj	2005-08-16 15:47:52.000000000 +0200
+++ ld/testsuite/ld-elfvers/vers30.ver	2005-08-16 15:56:15.000000000 +0200
@@ -0,0 +1,4 @@
+Version definitions:
+1 0x01 0x0966695f vers30.so
+2 0x00 0x079239b0 VERS_30.0
+
--- ld/testsuite/ld-elfvers/vers30.dsym.jj	2005-08-16 16:00:40.000000000 +0200
+++ ld/testsuite/ld-elfvers/vers30.dsym	2005-08-16 16:00:34.000000000 +0200
@@ -0,0 +1,5 @@
+[0]* g    DO \*ABS\*	[0]*  VERS_30.0   VERS_30.0
+[0-9a-f]* g    DF (.text|\*ABS\*)	[0-9a-f]*  VERS_30.0   global
+[0-9a-f]* g    DF (.text|\*ABS\*)	[0-9a-f]*  VERS_30.0   foo
+[0-9a-f]* g    DF (.text|\*ABS\*)	[0-9a-f]*  VERS_30.0   info
+[0-9a-f]* g    DF (.text|\*ABS\*)	[0-9a-f]*  VERS_30.0   extern

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]