The toc-data feature has been supported for assembly file generation. This patch handles the toc-data for object file generation.
Details
- Reviewers
shchenz DiggerLin hubert.reinterpretcast jhenderson - Group Reviewers
Restricted Project - Commits
- rG5ce0a26bd1cd: [XCOFF] handle the toc-data for object file generation.
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Time | Test | |
---|---|---|
60,040 ms | x64 debian > libFuzzer.libFuzzer::minimize_crash.test |
Event Timeline
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | ||
---|---|---|
2334 | Same as below, getExplicitSectionGlobal will not pass external globals. | |
2380 | The caller of this function SectionForGlobal is not allowed to pass external (or available externally) globals., So I don't think we need to care about XTY_ER type symbol here. See: /// This method computes the appropriate section to emit the specified global /// variable or function definition. This should not be passed external (or /// available externally) globals. MCSection *SectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const; We should handle the section for external TD symbols in getSectionForExternalReference() and adjust the order when we create the symbol TargetLoweringObjectFileXCOFF::getTargetSymbol(), i.e., handle external symbol first. | |
llvm/lib/MC/XCOFFObjectWriter.cpp | ||
465 | This can be put together with previous XMC_TC/XMC_TE case | |
638 | This must also be wrong now as for TOC direct external symbols, there will be no TOC slot for them, so the FiexedValue must always be 0. For example, for below case: int a = 20; extern int c; extern int b; int d = 10; int foo(void) { return a + b + c + d; } I get: 00000000 <.foo>: 0: 38 62 00 00 addi 3, 2, 0 00000002: R_TOC a 4: 38 82 ff ac addi 4, 2, -84 00000006: R_TOC b 8: 38 a2 ff ac addi 5, 2, -84 0000000a: R_TOC c c: 38 c2 00 04 addi 6, 2, 4 0000000e: R_TOC d a and d are correct, but b/c are obvious wrong. |
llvm/lib/MC/XCOFFObjectWriter.cpp | ||
---|---|---|
638 | Hmm, I made a test, with the assembly path, I get: 00000000 <.foo>: 0: 38 62 00 00 addi 3, 2, 0 00000002: R_TOC a 4: 80 63 00 00 lwz 3, 0(3) 8: 38 82 00 00 addi 4, 2, 0 ====> The fixed value is 0 here 0000000a: R_TOC b c: 80 84 00 00 lwz 4, 0(4) 10: 7c 63 22 14 add 3, 3, 4 14: 38 82 00 00 addi 4, 2, 0 ====> The fixed value is 0 here 00000016: R_TOC c 18: 80 84 00 00 lwz 4, 0(4) 1c: 7c 63 22 14 add 3, 3, 4 20: 38 82 00 04 addi 4, 2, 4 00000022: R_TOC d 24: 80 84 00 00 lwz 4, 0(4) 28: 7c 63 22 14 add 3, 3, 4 2c: 4e 80 00 20 blr This should be right. |
Addressed comments.
Changed the Fixup Value for TOC direct external symbols and added test lines for it in toc-data-const.ll.
Looks right now. Thanks for adding this support.
llvm/lib/MC/XCOFFObjectWriter.cpp | ||
---|---|---|
639 | Can we add comments here like: "For non toc-data external symbols, R_TOC type relocation will relocate to data symbols that have XCOFF::XTY_SD type csect. For toc-data external symbols, R_TOC type relocation will relocate to data symbols that have XCOFF_ER type csect. For XCOFF_ER kind symbols, there will be no TOC entry for them, so the FixedValue should always be 0."? |
Same as below, getExplicitSectionGlobal will not pass external globals.