[lld] r202111 - [LinkerScript] OUTPUT_FORMAT: Parse Quoted Strings

Chandler Carruth chandlerc at google.com
Tue Feb 25 00:03:19 PST 2014


On Mon, Feb 24, 2014 at 11:38 PM, Rui Ueyama <ruiu at google.com> wrote:

> On Mon, Feb 24, 2014 at 11:24 PM, Shankar Easwaran <
> shankare at codeaurora.org> wrote:
>
>> On 2/25/2014 1:14 AM, Rui Ueyama wrote:
>>
>>> On Mon, Feb 24, 2014 at 10:52 PM, Shankar Easwaran
>>> <shankare at codeaurora.org>wrote:
>>>
>>>  Hi Chandler, Rui,
>>>>
>>>> For example :-
>>>>
>>>> OUTPUT_FORMAT(x, "y", "z")
>>>>
>>>> We need to display an error for the above case, while
>>>>
>>>> OUTPUT_FORMAT("x", "y", "z") produces no error.
>>>>
>>>>  Both gave me error...
>>>
>> I am not sure about your ld version, but here it is :-
>>
>> $cat x
>> OUTPUT_FORMAT(x, "y", "z");
>>
>> $ld -T x
>> ld:x:1: syntax error
>> $cat y
>> OUTPUT_FORMAT("x", "y", "z");
>> $ld -T y
>> ld: no input files
>
>
> OUTPUT_FORMAT( x , "y", "z");
>
> does not print an error (x with surrounding whitespaces). It's not a
> matter of double quotes? I found that some parentheses in Linux's libc.so
> are surrounded by whitespace characters too, so something may be wrong with
> "(" handling in GNU LD, but it seems to be different issue from quoted
> string.
>

I think the errors from OUTPUT_FORMAT with a string which is not a bfdname
are red herrings. I don't think either GNU LD or Gold correctly recover
from random strings used here.

Note that on my x86 box, the three argument form won't even parse for me,
likely because of a lack of BE/LE support. Either way, *all three*
arguments to the OUTPUT_FORMAT command are 'bfdname's and not file names.
So if you want to error on using "s, you have to error on using "s in any
of the three arguments.

We can test what LD *actually* does by using a valid format and a single
output format argument:

% echo 'OUTPUT_FORMAT("elf64-x86-64");' > x
% ld -T x
ld: no input files
% ld.gold -T x
ld.gold: fatal error: no input files

So both ld and gold are happy with quotes around a bfdname.


Other sources of actual information are the manual pages for the linker
itself:

https://sourceware.org/binutils/docs/ld/Script-Format.html#Script-Format

This is hardly a specification, but it gives some clear indication of the
systax: commands followed by arguments. While it only mentions using quoted
strings for file names with random characters in them, that clearly can't
be taken literally. As I've shown above both linkers accept quoted strings
around 'bfdname' arguments to commands. Also, there are cases where it is
clearly required:

ENTRY("=foo");

There are manglings which use '=' in their symbol names so this could well
be necessary. Both linkers seem to accept it happily.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140225/be1ed40b/attachment.html>


More information about the llvm-commits mailing list