[llvm] [XCOFF] make related SD symbols as isFunction (PR #69553)
Chen Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 29 23:23:01 PDT 2023
https://github.com/chenzheng1030 updated https://github.com/llvm/llvm-project/pull/69553
>From 52d8c9da0432acc52e525a1789988fc412dbbf5d Mon Sep 17 00:00:00 2001
From: Chen Zheng <czhengsz at cn.ibm.com>
Date: Mon, 30 Oct 2023 01:42:43 -0400
Subject: [PATCH] ad XTY_SD type function symbol.
---
llvm/lib/Object/XCOFFObjectFile.cpp | 73 +++++++++++++++++--
llvm/test/CodeGen/PowerPC/aix-text.ll | 12 +--
.../CodeGen/PowerPC/aix-xcoff-funcsect.ll | 12 +--
.../tools/llvm-symbolizer/xcoff-sd-symbol.ll | 4 +-
4 files changed, 82 insertions(+), 19 deletions(-)
diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp
index 4c192aa37a7ecc7..6c7eeae0ed257f0 100644
--- a/llvm/lib/Object/XCOFFObjectFile.cpp
+++ b/llvm/lib/Object/XCOFFObjectFile.cpp
@@ -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 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, return `false`.
+ consumeError(SymbolAddressOrErr.takeError());
+ return false;
+ }
+
+ uint8_t NumberOfAuxEntries = getNumberOfAuxEntries();
+
+ // If this is the last main symbol table entry, there won't be XTY_LD type
+ // symbol below.
+ if (getEntryAddress() == getObject()->getSymbolEntryAddressByIndex(
+ getObject()->getNumberOfSymbolTableEntries() -
+ NumberOfAuxEntries - 1))
+ return true;
+
+ DataRefImpl Ref;
+ Ref.p = XCOFFObjectFile::getAdvancedSymbolEntryAddress(
+ getEntryAddress(), NumberOfAuxEntries + 1);
+ XCOFFSymbolRef NextSym = getObject()->toSymbolRef(Ref);
+ if (!NextSym.isCsectSymbol())
+ return true;
+
+ Expected<uint64_t> NextSymbolAddressOrErr = NextSym.getAddress();
+ if (!NextSymbolAddressOrErr) {
+ // If there is no address for next symbol, won't be same with the XTY_SD
+ // symbol.
+ consumeError(NextSymbolAddressOrErr.takeError());
+ return true;
+ }
+
+ if (SymbolAddressOrErr.get() != NextSymbolAddressOrErr.get())
+ return true;
+
+ // Check next symbol is XTY_LD. If so, this symbol is not a function.
+ Expected<XCOFFCsectAuxRef> NextCsectAuxEnt = NextSym.getXCOFFCsectAuxRef();
+ if (!NextCsectAuxEnt) {
+ // If the next symbol has no aux entries, it won't be a XTY_LD symbol.
+ consumeError(NextCsectAuxEnt.takeError());
+ return true;
+ }
+
+ if (NextCsectAuxEnt.get().getSymbolType() == XCOFF::XTY_LD)
+ return false;
+
+ return true;
+ }
+
+ if (CsectAuxRef.getSymbolType() == XCOFF::XTY_LD)
+ return true;
+
const int16_t SectNum = getSectionNumber();
Expected<DataRefImpl> SI = getObject()->getSectionByNum(SectNum);
if (!SI) {
diff --git a/llvm/test/CodeGen/PowerPC/aix-text.ll b/llvm/test/CodeGen/PowerPC/aix-text.ll
index a0d1d0e38d50225..7f7c4e95fe8394d 100644
--- a/llvm/test/CodeGen/PowerPC/aix-text.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-text.ll
@@ -17,13 +17,13 @@ entry:
ret i32 2
}
-; CHECKFS32: 00000000 l .text 00000000 (idx: {{[[:digit:]]*}}) [PR]
-; CHECKFS32-NEXT: 00000000 g .text {{([[:xdigit:]]{8})}} (idx: {{[[:digit:]]*}}) .text[PR]
-; CHECKFS32-NEXT: {{([[:xdigit:]]{8})}} g .text {{([[:xdigit:]]{8})}} (idx: {{[[:digit:]]*}}) .text2[PR]
+; CHECKFS32: 00000000 l .text 00000000 (idx: {{[[:digit:]]*}}) [PR]
+; CHECKFS32-NEXT: 00000000 g F .text {{([[:xdigit:]]{8})}} (idx: {{[[:digit:]]*}}) .text[PR]
+; CHECKFS32-NEXT: {{([[:xdigit:]]{8})}} g F .text {{([[:xdigit:]]{8})}} (idx: {{[[:digit:]]*}}) .text2[PR]
-; CHECKFS64: 0000000000000000 l .text 0000000000000000
-; CHECKFS64-NEXT: 0000000000000000 g .text {{([[:xdigit:]]{16})}} (idx: {{[[:digit:]]*}}) .text[PR]
-; CHECKFS64-NEXT: {{([[:xdigit:]]{16})}} g .text {{([[:xdigit:]]{16})}} (idx: {{[[:digit:]]*}}) .text2[PR]
+; CHECKFS64: 0000000000000000 l .text 0000000000000000
+; CHECKFS64-NEXT: 0000000000000000 g F .text {{([[:xdigit:]]{16})}} (idx: {{[[:digit:]]*}}) .text[PR]
+; CHECKFS64-NEXT: {{([[:xdigit:]]{16})}} g F .text {{([[:xdigit:]]{16})}} (idx: {{[[:digit:]]*}}) .text2[PR]
; CHECK32: 00000000 l .text {{([[:xdigit:]]{8})}} (idx: {{[[:digit:]]*}}) [PR]
; CHECK32-NEXT: {{([[:xdigit:]]{8})}} g F .text (csect: (idx: {{[[:digit:]]*}}) [PR]) 00000000 (idx: {{[[:digit:]]*}}) .text
diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect.ll
index 09c517c73dff296..2600fac01425da8 100644
--- a/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect.ll
@@ -117,9 +117,9 @@ entry:
; XCOFF32-NEXT: 00000000 l .text 00000000 (idx: 5) [PR]
; XCOFF32-NEXT: 00000000 g .text 00000019 (idx: 7) .foo[PR]
; XCOFF32-NEXT: 00000000 g F .text (csect: (idx: 7) .foo[PR]) 00000000 (idx: 9) .alias_foo
-; XCOFF32-NEXT: 00000020 g .text 00000020 .hidden (idx: 11) .hidden_foo[PR]
-; XCOFF32-NEXT: 00000040 g .text 00000059 (idx: 13) .bar[PR]
-; XCOFF32-NEXT: 000000c0 l .text 0000002a (idx: 15) .static_overalign_foo[PR]
+; XCOFF32-NEXT: 00000020 g F .text 00000020 .hidden (idx: 11) .hidden_foo[PR]
+; XCOFF32-NEXT: 00000040 g F .text 00000059 (idx: 13) .bar[PR]
+; XCOFF32-NEXT: 000000c0 l F .text 0000002a (idx: 15) .static_overalign_foo[PR]
; XCOFF32-NEXT: 000000ec g O .data 0000000c (idx: 17) foo[DS]
; XCOFF32-NEXT: 000000ec g O .data (csect: (idx: 17) foo[DS]) 00000000 (idx: 19) alias_foo
; XCOFF32-NEXT: 000000f8 g O .data 0000000c .hidden (idx: 21) hidden_foo[DS]
@@ -152,9 +152,9 @@ entry:
; XCOFF64-NEXT: 0000000000000000 l .text 0000000000000000 (idx: 5) [PR]
; XCOFF64-NEXT: 0000000000000000 g .text 0000000000000019 (idx: 7) .foo[PR]
; XCOFF64-NEXT: 0000000000000000 g F .text (csect: (idx: 7) .foo[PR]) 0000000000000000 (idx: 9) .alias_foo
-; XCOFF64-NEXT: 0000000000000020 g .text 0000000000000020 .hidden (idx: 11) .hidden_foo[PR]
-; XCOFF64-NEXT: 0000000000000040 g .text 0000000000000059 (idx: 13) .bar[PR]
-; XCOFF64-NEXT: 00000000000000c0 l .text 000000000000002a (idx: 15) .static_overalign_foo[PR]
+; XCOFF64-NEXT: 0000000000000020 g F .text 0000000000000020 .hidden (idx: 11) .hidden_foo[PR]
+; XCOFF64-NEXT: 0000000000000040 g F .text 0000000000000059 (idx: 13) .bar[PR]
+; XCOFF64-NEXT: 00000000000000c0 l F .text 000000000000002a (idx: 15) .static_overalign_foo[PR]
; XCOFF64-NEXT: 00000000000000f0 g O .data 0000000000000018 (idx: 17) foo[DS]
; XCOFF64-NEXT: 00000000000000f0 g O .data (csect: (idx: 17) foo[DS]) 0000000000000000 (idx: 19) alias_foo
; XCOFF64-NEXT: 0000000000000108 g O .data 0000000000000018 .hidden (idx: 21) hidden_foo[DS]
diff --git a/llvm/test/tools/llvm-symbolizer/xcoff-sd-symbol.ll b/llvm/test/tools/llvm-symbolizer/xcoff-sd-symbol.ll
index 781ac72933a1523..aedceb0227b8962 100644
--- a/llvm/test/tools/llvm-symbolizer/xcoff-sd-symbol.ll
+++ b/llvm/test/tools/llvm-symbolizer/xcoff-sd-symbol.ll
@@ -16,10 +16,10 @@ entry:
ret void
}
-; CHECK: ??
+; CHECK: .foo
; CHECK: ??:0:0
; CHECK-EMPTY:
-; CHECK: ??
+; CHECK: .foo1
; CHECK: ??:0:0
; CHECK-EMPTY:
More information about the llvm-commits
mailing list