[llvm-bugs] [Bug 48156] New: GC Optimization incorrectly determines when to keep init-sections

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 11 11:59:04 PST 2020


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

            Bug ID: 48156
           Summary: GC Optimization incorrectly determines when to keep
                    init-sections
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: wasm
          Assignee: unassignedbugs at nondot.org
          Reporter: trybka at google.com
                CC: llvm-bugs at lists.llvm.org, sbc at chromium.org

I believe the optimization added here (https://reviews.llvm.org/D85062) has an
error which was revealed after https://reviews.llvm.org/D89290.

Fairly small example here:
https://github.com/trybka/scraps/tree/master/lld-test

Depending on the link order, the `bug::Foo` object is never initialized in
`foo.cc`.

I believe this is due to an error in the logic in MarkLive.cpp and Symbols.cpp.

In MarkLive.cpp enqueue:
https://github.com/llvm/llvm-project/blob/dd8723d348c9e6182155233a62769024dd345c6b/lld/wasm/MarkLive.cpp#L62

The check `bool needInitFunctions = file && !file->isLive() &&
sym->isDefined();`
will be False for an undefined symbol.

However, when the symbol is marked live, it sets its file to live as well. In
the case of an undefined symbol, that is the wrong file.

Subsequent queued symbols actually in that file will then fail the
needInitFunctions check (as they are already apparently live) and so the init
is never added.

In the example above, __cxa_atexit would be undefined in foo.o. When marking
__cxa_atexit as "referenced", foo.o would be marked live, but the init is never
added.

-- 
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/20201111/4096e27c/attachment.html>


More information about the llvm-bugs mailing list