-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[XCOFF] make related SD symbols as isFunction #69553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9217eed
c9f1035
6fe33ae
47070d8
f0be247
ad3ceda
89a4f1a
44cbb15
4350bab
0a61806
19d2ff1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1242,21 +1242,57 @@ Expected<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 && | ||
CsectAuxRef.getStorageMappingClass() != XCOFF::XMC_GL) | ||
return false; | ||
|
||
if (CsectAuxRef.getStorageMappingClass() != XCOFF::XMC_PR) | ||
// A function definition should not be a common type symbol or an external | ||
// symbol. | ||
if (CsectAuxRef.getSymbolType() == XCOFF::XTY_CM || | ||
CsectAuxRef.getSymbolType() == XCOFF::XTY_ER) | ||
return false; | ||
|
||
const int16_t SectNum = getSectionNumber(); | ||
Expected<DataRefImpl> SI = getObject()->getSectionByNum(SectNum); | ||
if (!SI) | ||
return SI.takeError(); | ||
// If the next symbol is an XTY_LD type symbol with the 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 work around the fact that LLVM always generates below | ||
// symbol for -ffunction-sections: | ||
// m 0x00000000 .text 1 unamex **No Symbol** | ||
// a4 0x00000000 0 0 SD PR 0 0 | ||
// FIXME: remove or replace this meaningless symbol. | ||
if (getSize() == 0) | ||
return false; | ||
|
||
xcoff_symbol_iterator NextIt(this); | ||
// If this is the last main symbol table entry, there won't be an XTY_LD | ||
// type symbol below. | ||
if (++NextIt == getObject()->symbol_end()) | ||
return true; | ||
|
||
if (cantFail(getAddress()) != cantFail(NextIt->getAddress())) | ||
return true; | ||
chenzheng1030 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Check next symbol is XTY_LD. If so, this symbol is not a function. | ||
Expected<XCOFFCsectAuxRef> NextCsectAuxEnt = NextIt->getXCOFFCsectAuxRef(); | ||
if (!NextCsectAuxEnt) | ||
return NextCsectAuxEnt.takeError(); | ||
|
||
if (NextCsectAuxEnt.get().getSymbolType() == XCOFF::XTY_LD) | ||
return false; | ||
|
||
return (getObject()->getSectionFlags(SI.get()) & XCOFF::STYP_TEXT); | ||
return true; | ||
} | ||
|
||
if (CsectAuxRef.getSymbolType() == XCOFF::XTY_LD) | ||
return true; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In current implement, I do not think the following code(which check for section) will be running.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, I think below codes seem not be needed even before this change. I don't think a If so, maybe we can add an NFC patch to remove this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
since you almost rewrite the isFunction(), I think we can delete the code in the PR, what is your option @jh7370 , @stephenpeckham There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've got no particularly strong preference either way, but if there's a clear improvement that could be made without this patch, I don't think it hurts spinning it off into its own PR. |
||
return createError( | ||
"symbol csect aux entry with index " + | ||
Twine(getObject()->getSymbolIndex(CsectAuxRef.getEntryAddress())) + | ||
" has invalid symbol type " + | ||
Twine::utohexstr(CsectAuxRef.getSymbolType())); | ||
} | ||
|
||
bool XCOFFSymbolRef::isCsectSymbol() const { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## Check that llvm-objdump --syms reports an error when | ||
## the symbol type in the csect aux entry of a symbol is not valid. | ||
|
||
## Check XCOFF32 | ||
# RUN: yaml2obj -DMAGICNUMBER=0x1DF %s -o %t1 | ||
# RUN: not llvm-objdump --syms %t1 2>&1 | FileCheck %s -DOBJ=%t1 | ||
|
||
## Check XCOFF64 | ||
# RUN: yaml2obj -DMAGICNUMBER=0x1F7 %s -o %t2 | ||
# RUN: not llvm-objdump --syms %t2 2>&1 | FileCheck %s -DOBJ=%t2 | ||
|
||
# CHECK: error: '[[OBJ]]': symbol csect aux entry with index 2 has invalid symbol type 5 | ||
|
||
--- !XCOFF | ||
jh7370 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FileHeader: | ||
MagicNumber: [[MAGICNUMBER]] | ||
Sections: | ||
- Name: .text | ||
Flags: [ STYP_TEXT ] | ||
Symbols: | ||
- Name: .file | ||
Section: N_DEBUG | ||
NumberOfAuxEntries: 0 | ||
Type: 0x0 | ||
StorageClass: C_FILE | ||
- Name: test | ||
Section: .text | ||
NumberOfAuxEntries: 1 | ||
StorageClass: C_EXT | ||
AuxEntries: | ||
- Type: AUX_CSECT | ||
SymbolAlignmentAndType: 5 | ||
StorageMappingClass: XMC_PR |
Uh oh!
There was an error while loading. Please reload this page.