elf: Treat undefined version as hidden

Message ID 20210801143104.2388536-1-hjl.tools@gmail.com
State New
Headers show
Series
  • elf: Treat undefined version as hidden
Related show

Commit Message

Alan Modra via Binutils Aug. 1, 2021, 2:31 p.m.
Since undefined version can't be used to resolve any references, treat
it as hidden.

bfd/

	PR binutils/28158
	* elf.c (_bfd_elf_get_symbol_version_string): Treat undefined
	version as hidden.

ld/

	PR binutils/28158
	* testsuite/ld-elfvers/vers2.dsym: Updated.
	* testsuite/ld-elfvers/vers3.dsym: Likewise.
	* testsuite/ld-elfvers/vers6.dsym: Likewise.
	* testsuite/ld-elfvers/vers19.dsym: Likewise.
	* testsuite/ld-elfvers/vers22.dsym: Likewise.
	* testsuite/ld-elfvers/vers28c.dsym: Likewise.
---
 bfd/elf.c                            | 1 +
 ld/testsuite/ld-elfvers/vers19.dsym  | 2 +-
 ld/testsuite/ld-elfvers/vers2.dsym   | 2 +-
 ld/testsuite/ld-elfvers/vers22.dsym  | 2 +-
 ld/testsuite/ld-elfvers/vers28c.dsym | 2 +-
 ld/testsuite/ld-elfvers/vers3.dsym   | 2 +-
 ld/testsuite/ld-elfvers/vers6.dsym   | 6 +++---
 7 files changed, 9 insertions(+), 8 deletions(-)

-- 
2.31.1

Comments

Alan Modra via Binutils Aug. 2, 2021, 2:03 a.m. | #1
On Sun, Aug 01, 2021 at 07:31:04AM -0700, H.J. Lu via Binutils wrote:
> Since undefined version can't be used to resolve any references,


Testcase please, specifically when the "undefined version" is that
for a .dynbss symbol definition.  I did a little experiment myself and
I don't think you are correct.  My testcase might be faulty, so please
write one yourself.

Mine had
a) One shared lib with a definition of a variable foo, a function to
print foo seen by that lib, and another function to set a hidden alias
of foo.  foo was made versioned using a version script.
b) A second lib with a reference to a foo, a function to print foo
seen by the lib, and another function to set foo.  No version script
was used.
c) A main program with a text reference to foo in order to force a
dynbss copy of foo.

Output is

b foo = 1
c foo = 1
c setting foo to 2
b foo = 2
c foo = 2
b setting foo alias to 3
b foo = 2
c foo = 2

readelf shows there is just one dynamic foo in the main program, the
dynbss copy: GLOBAL DEFAULT 25 foo@VER (2).

LD_DEBUG=all | grep foo shows
   3541018:	symbol=foo;  lookup in file=./prxxxxx [0]
   3541018:	binding file ./prxxxxxc.so [0] to ./prxxxxx [0]: normal symbol `foo'
   3541018:	symbol=foo;  lookup in file=./prxxxxx [0]
   3541018:	binding file ./prxxxxxb.so [0] to ./prxxxxx [0]: normal symbol `foo' [VER]
   3541018:	symbol=foo;  lookup in file=./prxxxxx [0]
   3541018:	binding file ./prxxxxx [0] to ./prxxxxx [0]: normal symbol `foo' [VER]
   3541018:	symbol=foo;  lookup in file=./prxxxxxb.so [0]
   3541018:	binding file ./prxxxxx [0] to ./prxxxxxb.so [0]: normal symbol `foo' [VER]

-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/bfd/elf.c b/bfd/elf.c
index d0898855de8..5941eeb010b 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1944,6 +1944,7 @@  _bfd_elf_get_symbol_version_string (bfd *abfd, asymbol *symbol,
 		{
 		  if (a->vna_other == vernum)
 		    {
+		      *hidden = true;
 		      version_string = a->vna_nodename;
 		      break;
 		    }
diff --git a/ld/testsuite/ld-elfvers/vers19.dsym b/ld/testsuite/ld-elfvers/vers19.dsym
index a77f9490127..798466fb8bd 100644
--- a/ld/testsuite/ld-elfvers/vers19.dsym
+++ b/ld/testsuite/ld-elfvers/vers19.dsym
@@ -1 +1 @@ 
-[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +VERS_2\.0 +(0x[0-9a-f]+ )?_?show_foo
+[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +\(VERS_2\.0\) +(0x[0-9a-f]+ )?_?show_foo
diff --git a/ld/testsuite/ld-elfvers/vers2.dsym b/ld/testsuite/ld-elfvers/vers2.dsym
index 30ba91b82b4..f820fdc9717 100644
--- a/ld/testsuite/ld-elfvers/vers2.dsym
+++ b/ld/testsuite/ld-elfvers/vers2.dsym
@@ -1,3 +1,3 @@ 
-[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +VERS_2\.0 +(0x[0-9a-f]+ )?_?show_foo
+[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +\(VERS_2\.0\) +(0x[0-9a-f]+ )?_?show_foo
 0+ g +DO \*ABS\*	0+ +VERS_XXX_1\.1 VERS_XXX_1\.1
 [0-9a-f]+ g +DF (\.text|\.opd|\*ABS\*)	[0-9a-f]+ +VERS_XXX_1\.1 (0x[0-9a-f]+ )?_?show_xyzzy
diff --git a/ld/testsuite/ld-elfvers/vers22.dsym b/ld/testsuite/ld-elfvers/vers22.dsym
index db2aeec4bc3..65a183345a2 100644
--- a/ld/testsuite/ld-elfvers/vers22.dsym
+++ b/ld/testsuite/ld-elfvers/vers22.dsym
@@ -1 +1 @@ 
-[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +VERS\.0 +(0x[0-9a-f]+ )?_?bar
+[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +\(VERS\.0\) +(0x[0-9a-f]+ )?_?bar
diff --git a/ld/testsuite/ld-elfvers/vers28c.dsym b/ld/testsuite/ld-elfvers/vers28c.dsym
index 7ad56789eea..a575eff0d2c 100644
--- a/ld/testsuite/ld-elfvers/vers28c.dsym
+++ b/ld/testsuite/ld-elfvers/vers28c.dsym
@@ -1 +1 @@ 
-[0-9a-f]+[ 	]+DF[ 	]+\*UND\*[	]+[0-9a-f]+[ 	]+VERS\.0[ 	]+(0x[0-9a-f]+ )?_?foo
+[0-9a-f]+[ 	]+DF[ 	]+\*UND\*[	]+[0-9a-f]+[ 	]+\(VERS\.0\)[ 	]+(0x[0-9a-f]+ )?_?foo
diff --git a/ld/testsuite/ld-elfvers/vers3.dsym b/ld/testsuite/ld-elfvers/vers3.dsym
index a77f9490127..798466fb8bd 100644
--- a/ld/testsuite/ld-elfvers/vers3.dsym
+++ b/ld/testsuite/ld-elfvers/vers3.dsym
@@ -1 +1 @@ 
-[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +VERS_2\.0 +(0x[0-9a-f]+ )?_?show_foo
+[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +\(VERS_2\.0\) +(0x[0-9a-f]+ )?_?show_foo
diff --git a/ld/testsuite/ld-elfvers/vers6.dsym b/ld/testsuite/ld-elfvers/vers6.dsym
index a5a805377ca..6d073127648 100644
--- a/ld/testsuite/ld-elfvers/vers6.dsym
+++ b/ld/testsuite/ld-elfvers/vers6.dsym
@@ -1,4 +1,4 @@ 
 [0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +Base +(0x[0-9a-f]+ )?_?show_foo
-[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +VERS_2.0 +(0x[0-9a-f]+ )?_?show_foo
-[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +VERS_1.2 +(0x[0-9a-f]+ )?_?show_foo
-[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +VERS_1.1 +(0x[0-9a-f]+ )?_?show_foo
+[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +\(VERS_2.0\) +(0x[0-9a-f]+ )?_?show_foo
+[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +\(VERS_1.2\) +(0x[0-9a-f]+ )?_?show_foo
+[0-9a-f]+ +DF \*UND\*	[0-9a-f]+ +\(VERS_1.1\) +(0x[0-9a-f]+ )?_?show_foo