[llvm-bugs] [Bug 40396] New: DEFINED(foo) always evaluates to true if foo is also defined in the script

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 21 22:48:02 PST 2019


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: unassignedbugs at nondot.org
          Reporter: pkmx.tw at gmail.com
                CC: llvm-bugs at lists.llvm.org, peter.smith at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190122/7a754b3e/attachment.html>


More information about the llvm-bugs mailing list