[PATCH] D139516: [XCOFF] handle the toc-data for object file generation.

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 23 01:29:30 PST 2022


shchenz added inline comments.


================
Comment at: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp:2334
+                                 GO->isDeclarationForLinker() ? XCOFF::XTY_ER
+                                                              : XCOFF::XTY_SD),
           /* MultiSymbolsAllowed*/ true);
----------------
Same as below, `getExplicitSectionGlobal` will not pass external globals.


================
Comment at: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp:2380
+          Name, Kind,
+          XCOFF::CsectProperties(XCOFF::XMC_TD, GO->isDeclarationForLinker()
+                                                    ? XCOFF::XTY_ER
----------------
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.


================
Comment at: llvm/lib/MC/XCOFFObjectWriter.cpp:465
     return TOCCsects;
   case XCOFF::XMC_TD:
+    assert(XCOFF::XTY_SD == MCSec->getCSectType() &&
----------------
This can be put together with previous XMC_TC/XMC_TE case


================
Comment at: llvm/lib/MC/XCOFFObjectWriter.cpp:638
 
     FixedValue = TOCEntryOffset;
   }
----------------
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.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139516/new/

https://reviews.llvm.org/D139516



More information about the llvm-commits mailing list