[llvm] [XCOFF] make related SD symbols as isFunction (PR #69553)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 30 08:19:10 PDT 2023
================
@@ -1242,15 +1242,78 @@ bool XCOFFSymbolRef::isFunction() const {
const XCOFFCsectAuxRef CsectAuxRef = ExpCsectAuxEnt.get();
- // A function definition should be a label definition.
- // FIXME: This is not necessarily the case when -ffunction-sections is
- // enabled.
- if (!CsectAuxRef.isLabel())
+ if (CsectAuxRef.getStorageMappingClass() != XCOFF::XMC_PR)
return false;
- if (CsectAuxRef.getStorageMappingClass() != XCOFF::XMC_PR)
+ // A function definition should not be a common type symbol or a external
+ // symbol.
+ if (CsectAuxRef.getSymbolType() == XCOFF::XTY_CM ||
+ CsectAuxRef.getSymbolType() == XCOFF::XTY_ER)
return false;
+ // If the next symbol is a XTY_LD type symbol with same address, this XTY_SD
+ // symbol is not a function. Otherwise this is a function symbol for
+ // -ffunction-sections.
+ if (CsectAuxRef.getSymbolType() == XCOFF::XTY_SD) {
+ // If this is a csect with size 0, it won't be a function definition.
+ // This is used to hack situation that llvm always generates below symbol
+ // for -ffunction-sections:
+ // m 0x00000000 .text 1 unamex **No Symbol**
+ // a4 0x00000000 0 0 SD PR 0 0
+ if (getSize() == 0)
+ return false;
+
+ Expected<uint64_t> SymbolAddressOrErr = getAddress();
+ if (!SymbolAddressOrErr) {
+ // If there is no address for this symbol, won't be a function.
+ consumeError(SymbolAddressOrErr.takeError());
+ return false;
+ }
----------------
diggerlin wrote:
in XCOFF getAddress() will never return an error actually.
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Object/ObjectFile.h#L462C1-L464C2
will call
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Object/XCOFFObjectFile.cpp#L257C1-L259C2
will call
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Object/XCOFFObjectFile.h#L791C1-L793C4
https://github.com/llvm/llvm-project/pull/69553
More information about the llvm-commits
mailing list