[PATCH] D71551: [AIX][XCOFF]Implement mergeable const
Digger via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 6 07:22:55 PST 2020
DiggerLin marked an inline comment as done.
DiggerLin added inline comments.
================
Comment at: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp:1870
+ if (Kind.isMergeableConst()) {
+ return getContext().getXCOFFSection(".rodata.cst",
----------------
hubert.reinterpretcast wrote:
> DiggerLin wrote:
> > DiggerLin wrote:
> > > hubert.reinterpretcast wrote:
> > > > DiggerLin wrote:
> > > > > hubert.reinterpretcast wrote:
> > > > > > As @jasonliu mentioned, there is not much precedent for this in the context of AIX. What is the rationale for not using the normal read-only data section?
> > > > > I implemented the Mergeable const as gcc did.
> > > > > 1 .gcc use a separate csect for all mergeable const. gcc generate is as
> > > > > .csect _mergeableconst.ro_[RO],4
> > > > > .align 3
> > > > > cnst32:
> > > > > .long 1073741824
> > > > > .long 50
> > > > > .space 24
> > > > > .globl cnst16
> > > > > .align 3
> > > > > cnst16:
> > > > > .long 1073741824
> > > > > .long 22
> > > > > .space 8
> > > > > .globl cnst8
> > > > > .align 2
> > > > > cnst8:
> > > > > .long 1073741832
> > > > > .space 4
> > > > > .globl cnst4
> > > > > .align 1
> > > > > cnst4:
> > > > > .short 16392
> > > > > .space 2
> > > > > .csect .text[PR]
> > > > > _section_.text:
> > > > > .csect .data[RW],4
> > > > > .long _section_.text
> > > > > 2. xlc use separate csect const32, const16,const8, const4 for mergeable const32 , mergeable const16, mergeable const8. mergeable const4.
> > > > >
> > > > >
> > > > > .csect cnst32{RO}, 3
> > > > > .long 0x40000000 # "@\0\0\0"
> > > > > .long 0x00000032 # "\0\0\0002"
> > > > > .long 0x00000000 # "\0\0\0\0"
> > > > > .long 0x00000000 # "\0\0\0\0"
> > > > > .long 0x00000000 # "\0\0\0\0"
> > > > > .long 0x00000000 # "\0\0\0\0"
> > > > > .long 0x00000000 # "\0\0\0\0"
> > > > > .long 0x00000000 # "\0\0\0\0"
> > > > >
> > > > > .csect cnst16{RO}, 3
> > > > > .long 0x40000000 # "@\0\0\0"
> > > > > .long 0x00000016 # "\0\0\0\026"
> > > > > .long 0x00000000 # "\0\0\0\0"
> > > > > .long 0x00000000 # "\0\0\0\0"
> > > > >
> > > > > .csect cnst8{RO}, 3
> > > > > .long 0x40000008 # "@\0\0\b"
> > > > > .long 0x00000000 # "\0\0\0\0"
> > > > >
> > > > > .csect cnst4{RO}
> > > > > .long 0x40080000 # "@\b\0\0"
> > > > >
> > > > In the assembly you list, the naming of the labels (for the GCC case) or csects (for the XL case) is suspect (they are indicative of declared variables). Declared variables are not mergeable in the general sense.
> > > >
> > > > It is observed that GCC on AIX uses `.ro` and `.rw` as suffixes for read-only sections; however, the naming does not seem to indicate "mergeable" as a factor.
> > > >
> > > yes, you are correct, the for gcc and xlc in the aix , I used the source code as
> > >
> > > typedef struct {
> > > unsigned long long id;
> > > unsigned int option1;
> > > unsigned long long option2;
> > > unsigned int option3;
> > > } Merge_cnst32;
> > >
> > > typedef struct {
> > > unsigned long long id;
> > > unsigned int options;
> > > } Merge_cnst16;
> > >
> > > typedef struct {
> > > unsigned int id;
> > > unsigned int options;
> > > } Merge_cnst8;
> > >
> > > typedef struct {
> > > unsigned short id;
> > > unsigned char options;
> > > } Merge_cnst4;
> > >
> > > //int main() {
> > > Merge_cnst32 const cnst32 = { .id = 0x4000000000000032ULL };
> > > Merge_cnst16 const cnst16 = { .id = 0x4000000000000016ULL };
> > > Merge_cnst8 const cnst8 = { .id = 0x40000008 };
> > > Merge_cnst4 const cnst4 = { .id = 0x4008 };
> > > //}
> > >
> > > if I uncomment the int main() { , gcc and xlc will not generate any csect for the cnst32 ,cnst16,cnst8. cnst32 or they also do not put the value in any csect. it put the value in the text asm instruction directly.
> > and in the linux , the llvm put the mergeabe const in the readonly as
> >
> > .csect .rodata.cst[RO]
> > .align 4
> > .L__const.main.cnst32:
> > .llong 4611686018427387954 # 0x4000000000000032
> > .long 0 # 0x0
> > .space 4
> > .llong 0 # 0x0
> > .long 0 # 0x0
> > .space 4
> > .align 3
> > .L__const.main.cnst16:
> > .llong 4611686018427387926 # 0x4000000000000016
> > .long 0 # 0x0
> > .space 4
> > .align 3
> > .L__const.main.cnst8:
> > .long 1073741832 # 0x40000008
> > .long 0 # 0x0
> > .align 3
> > .L__const.main.cnst4:
> > .short 16392 # 0x4008
> > .byte 0 # 0x0
> > .space 1
> >
> > it also put the merge const in the a new .csect .rodata.cst[RO] .
> The description of the Linux behaviour seems strange to me. I would expect a `.section` directive.
>
> In any case, it seems we have established that neither XL nor GCC on AIX produce special mergeable-const sections. We should either create the sections as LLVM does for ELF (knowing that it really does not do any merging), or we should just treat the object as being plain read-only). For the strings, we went with the create-like-for-ELF route for now (which has no negative effect that I know of). For the mergeable-const cases, it seems we save on a sizeable amount of code if we just treat them as plain read-only.
Sorry. post the wrong information for the linux elf. it should be
.type .L__const.main.cnst32, at object # @__const.main.cnst32
.section .rodata.cst32,"aM", at progbits,32
.p2align 4
.L__const.main.cnst32:
.long 1073741824 # 0x4000000000000032
.long 50
.long 0 # 0x0
.space 4
.long 0 # 0x0
.long 0
.long 0 # 0x0
.space 4
.size .L__const.main.cnst32, 32
.type .L__const.main.cnst16, at object # @__const.main.cnst16
.section .rodata.cst16,"aM", at progbits,16
.p2align 3
.L__const.main.cnst16:
.long 1073741824 # 0x4000000000000016
.long 22
.long 0 # 0x0
.space 4
.size .L__const.main.cnst16, 16
.type .L__const.main.cnst8, at object # @__const.main.cnst8
.section .rodata.cst8,"aM", at progbits,8
.p2align 3
.L__const.main.cnst8:
.long 1073741832 # 0x40000008
.long 0 # 0x0
.size .L__const.main.cnst8, 8
.type .L__const.main.cnst4, at object # @__const.main.cnst4
.section .rodata.cst4,"aM", at progbits,4
.p2align 3
.L__const.main.cnst4:
.short 16392 # 0x4008
.byte 0 # 0x0
.space 1
.size .L__const.main.cnst4, 4
.section ".note.GNU-stack","", at progbits
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71551/new/
https://reviews.llvm.org/D71551
More information about the llvm-commits
mailing list