[llvm-bugs] [Bug 47533] New: LLD is doing undesirable identical code folding when invoked with -Wl, --icf=safe
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Sep 15 03:47:01 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47533
Bug ID: 47533
Summary: LLD is doing undesirable identical code folding when
invoked with -Wl,--icf=safe
Product: lld
Version: unspecified
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: ELF
Assignee: unassignedbugs at nondot.org
Reporter: arpit07531 at gmail.com
CC: llvm-bugs at lists.llvm.org, smithp352 at googlemail.com
Please find the example source code where this issue is reproducible here -
https://github.com/arpit07531/llvm-lld-icf-bug/tree/master/helloWorldNative2
I basically have the following template method. I invoke this method for
various exception types to determine if the input exception_ptr is of the same
type. Please note that here exception types are not inheriting std::exception
class.
template<class T>
__attribute__((noinline))
bool IsError(const std::exception_ptr &err) noexcept
{
if (!err)
{
return false;
}
try
{
std::rethrow_exception(err);
}
catch (const T &)
{
return true;
}
catch (...)
{
return false;
}
}
Example Usage of this method :
---------------------------------
bool result1 =
CustomException::IsError<CustomException::Exception_Type1>(std::make_exception_ptr(CustomException::Exception_Type1{0x01}));
bool result2 =
CustomException::IsError<CustomException::Exception_Type2>(std::make_exception_ptr(CustomException::Exception_Type2{0x02}));
bool result3 =
CustomException::IsError<CustomException::Exception_Type3>(std::make_exception_ptr(CustomException::Exception_Type3{0x03}));
Expected Behavior
--------------------------------
result1, result2 and result3 should all return true.
Actual Behavior
--------------------------------
result 1 is true,
result 2 is false.
result 3 is false.
Issue here
--------------------------------
Please refer to the nm output below. Linker is treating IsError implementations
for different types as Identical code, and retaining implementations for only
one of the template types and folding the rest.
A single implementation can't cater to all template types in this case, as
IsError method will alwasy return false for the template types for which
IsError implementation is folded by the linker, because the flow will always
reach catch(...) for them.
nm -C -a
"D:\offpkg\ASProjects\helloWorldNative2\app\build\intermediates\merged_native_libs\debug\out\lib\armeabi-v7a\libnative-lib.so"
|grep IsError
00015629 t bool
CustomException::IsError<CustomException::Exception_Type1>(std::exception_ptr
const&)
00015629 t bool
CustomException::IsError<CustomException::Exception_Type2>(std::exception_ptr
const&)
00015629 t bool
CustomException::IsError<CustomException::Exception_Type3>(std::exception_ptr
const&)
How to repro this issue:
-------------------------
- Explicitly mark the IsError method as no-inline.
- Compiler flags - -ffunction-sections -fdata-sections -Os -flto=thin.
- Linker flags - -Wl,--gc-sections -flto=thin -Wl,--icf-safe.
- LLD versions - issue is reproducible on all lld versions.
--
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/20200915/c4d04f96/attachment.html>
More information about the llvm-bugs
mailing list