This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Versionscript: do not treat non-wildcarded names as wildcards.
ClosedPublic

Authored by grimar on Sep 5 2016, 4:41 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 70317.Sep 5 2016, 4:41 AM
grimar retitled this revision from to [ELF] - Versionscript: do not treat non-wildcarded names as wildcards..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: grimar, evgeny777, llvm-commits, emaste.
ruiu edited edge metadata.Sep 6 2016, 4:30 PM

With this patch, the existence of double quotes affects how strings will be interpreted later. Such grammar seems really weird to me. Are you sure that the grammar is correct? You are making

foo::*

to match foo::bar, while

"foo::*"

does not match foo::bar.

test/ELF/version-script-extern-exact.s
6 ↗(On Diff #70317)

You need to escape '"' in this line too.

grimar added a comment.Sep 7 2016, 2:16 AM
In D24229#535364, @ruiu wrote:

With this patch, the existence of double quotes affects how strings will be interpreted later. Such grammar seems really weird to me. Are you sure that the grammar is correct?

Yes, I believe so. From GNU Liner specs
(p.66 https://web.eecs.umich.edu/~prabal/teaching/resources/eecs373/Linker.pdf):

"Demangled names may contains spaces and other special characters. As described above,
you can use a glob pattern to match demangled names, or you can use a double-quoted
string to match the string exactly. In the latter case, be aware that minor differences (such
as differing whitespace) between the version script and the demangler output will cause a
mismatch."

Behavior is expected, I re-checked both gold and ld:

Used version script:

LIBSAMPLE_1.0 {
   global:            
     extern "C++" {  
       "foo*";   
   };                  
 };                                     

Code:
.text
.globl _Z3fooi
.type _Z3fooi,@function
_Z3fooi:
retq

llvm-mc -filetype=obj -triple=x86_64-pc-linux test1.s -o test1.o
ld --version-script test.script -shared test1.o -o out
llvm-readobj -V out

foo is unversioned:

Symbol {
  Version: 1
  Name: _Z3fooi@
}

But if I remove quotes then it has version LIBSAMPLE_1.0:

LIBSAMPLE_1.0 {
   global:            
     extern "C++" {  
       foo*;   
   };                  
 };    

  Symbol {
    Version: 2
    Name: _Z3fooi@@LIBSAMPLE_1.0
  }

That actually looks as simple and nice rule for me. Value in quotes is always exact match only and never a wildcard.

grimar updated this revision to Diff 70512.Sep 7 2016, 2:51 AM
grimar edited edge metadata.
  • Addressed review comment.
test/ELF/version-script-extern-exact.s
6 ↗(On Diff #70317)

Right. This bug we also have in other testcases, e.g version-script-extern-wildcards.s. I`ll fix.

ruiu added a comment.Sep 7 2016, 3:18 PM

If you think of this, that grammar looks very weird because it lacks a way to write a glob pattern containing a whitespace character. For example, if you want to write a pattern that matches strings starting with "foo " followed by any characters, you need this glob pattern: "foo *". However, if you write that in a linker script, it means the literal string "foo *" instead of a glob pattern, because the token is quoted. That means there's no way to express that in the linker script.

Being said that, this is what GNU does, and linker scripts are written that way, so unfortunately there's no way other than implementing the same thing.

ELF/ScriptParser.cpp
63 ↗(On Diff #70512)

Please add a comment why we leave double quotes in a resulting token.

// Quoted token. Note that double-quote characters are parts of a token
// because, in a glob match context, only unquoted tokens are interpreted
// as glob patterns. Double-quoted tokens are literal patterns in that context.
test/ELF/version-script-extern-exact.s
7 ↗(On Diff #70512)
echo "FOO { global: extern \"C++\" \"aaa*\"; }; };" > %t.script
grimar updated this revision to Diff 70663.Sep 8 2016, 2:13 AM
  • Addressed review comments.
  • Make checks in tests to be explicit.
ELF/ScriptParser.cpp
63 ↗(On Diff #70512)

Done.

test/ELF/version-script-extern-exact.s
7 ↗(On Diff #70512)

Done.

ruiu accepted this revision.Sep 8 2016, 3:16 PM
ruiu edited edge metadata.

LGTM

This revision is now accepted and ready to land.Sep 8 2016, 3:16 PM
This revision was automatically updated to reflect the committed changes.