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

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 4 20:44:56 PST 2023


shchenz added inline comments.


================
Comment at: llvm/lib/MC/XCOFFObjectWriter.cpp:638
 
     FixedValue = TOCEntryOffset;
   }
----------------
Esme wrote:
> shchenz wrote:
> > 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.
> It seems that the behavior of AIX's `as` is the same? So I'm a bit confused about this.
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.


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