https://bugs.llvm.org/show_bug.cgi?id=51961

            Bug ID: 51961
           Summary: quotes in linker script symbol names incorrectly
                    retained
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: ELF
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

from the GNU linker docs:
> https://sourceware.org/binutils/docs/ld.html#Symbols
> Unless quoted, symbol names start with a letter, underscore, or period and
> may include letters, digits, underscores, periods, and hyphens. Unquoted
> symbol names must not conflict with any keywords. You can specify a symbol
> which contains odd characters or has the same name as a keyword by
> surrounding the symbol name in double quotes:
> 
> "SECTION" = 9;
> "with a space" = "also with a space" + 10;

simple test case:
$ cat test.c
int main(){}
$ cat test.lds
symtest1 = 1;
"symtest2" = 2;
"symtest3" = "symtest1";
"symtest@3" = 3;
"symtest@4" = symtest1;
"symtest@5" = "symtest1";
"symtest 6" = 6;
"symtest 7" = "symtest 6";

checking with ld.bfd looks correct:
$ clang test.c -fuse-ld=bfd test.lds
$ readelf -sW a.out | grep symtest
     3: 0000000000000003     0 NOTYPE  LOCAL  DEFAULT  ABS symtest@3
     4: 0000000000000001     0 NOTYPE  LOCAL  DEFAULT  ABS symtest@5
     5: 0000000000000001     0 NOTYPE  LOCAL  DEFAULT  ABS symtest@4
    14: 0000000000000002     0 NOTYPE  GLOBAL DEFAULT  ABS symtest2
    15: 0000000000000006     0 NOTYPE  GLOBAL DEFAULT  ABS symtest 6
    24: 0000000000000001     0 NOTYPE  GLOBAL DEFAULT  ABS symtest3
    26: 0000000000000001     0 NOTYPE  GLOBAL DEFAULT  ABS symtest1
    27: 0000000000000006     0 NOTYPE  GLOBAL DEFAULT  ABS symtest 7

using lld fails outright due to RHS quoting:
$ clang test.c -fuse-ld=lld test.lds 
ld.lld: error: test.lds:3: malformed number: "symtest1"
>>> "symtest3" = "symtest1";
>>>              ^
clang-12: error: linker command failed with exit code 1 (use -v to see
invocation)

but even after removing those shows lld generates invalid symbols:
$ readelf -sW a.out | grep symtest
    16: 0000000000000001     0 NOTYPE  GLOBAL DEFAULT  ABS symtest1
    17: 0000000000000002     0 NOTYPE  GLOBAL DEFAULT  ABS "symtest2"
    18: 0000000000000003     0 NOTYPE  GLOBAL DEFAULT  ABS "symtest@3"
    19: 0000000000000001     0 NOTYPE  GLOBAL DEFAULT  ABS "symtest@4"
    20: 0000000000000006     0 NOTYPE  GLOBAL DEFAULT  ABS "symtest 6"

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to