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

            Bug ID: 40396
           Summary: DEFINED(foo) always evaluates to true if foo is also
                    defined in the script
           Product: lld
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: ELF
          Assignee: unassignedb...@nondot.org
          Reporter: pkmx...@gmail.com
                CC: llvm-bugs@lists.llvm.org, peter.sm...@linaro.org

$ cat test.ld
SECTIONS {
  foo = DEFINED(foo) ? foo : 0x1000;
  ASSERT ( foo == 0x1000 , "should not happen" )
}

$ echo | clang -xc - -c -o empty.o

$ ld.lld empty.o -Ttest.ld
ld.lld: error: should not happen

This is a documented usage in bfd's ld manual
(https://sourceware.org/binutils/docs/ld/Builtin-Functions.html#Builtin-Functions),
where foo should retain its value if it is already set prior to the statement
(via --defsym or other methods), or otherwise set to a default value 0x1000.
However, lld always evaluates it to 0.

The root cause seems to be rL323729 that adds all symbol assignments to the
symbol table as a dummy `Defined` absolute symbol of value 0, which causes the
DEFINED() builtin to always evaluate to true.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to