Discussion:
Power 64 ELFv2 w.r.t toc(cmodel=medium) on windows.
Umesh Kalappa
2018-10-25 15:53:05 UTC
Permalink
Hi All,

For the below code (test.c)

int foo()
{
printf("Hello World");
}

On linux :
ccpc -mcpu=e6500 -mno-altivec -mabi=no-altivec -D_WRS_HARDWARE_FP
-mabi=elfv2 -mcmodel=med -mhard-float -S test.c

linux asm :
the constant string fetched like

addis 3,2,***@toc@ha
addi 3,3,***@toc@l

where offset signed 32 bit used relatively to toc base on linux as
expected for the medium code model .
and the relocation entry will be generated by gas :
R_PPC64_TOC16_HA and R_PPC64_TOC16_LO

For Windows :

same command and windows asm looks like

la 3,***@toc(2)

where offset used signed 16 bit used relatively to toc base why it so ?.
and the relocation entry will be :
R_PPC64_TOC16 (signed 16 bit offset )

why this difference and when we greping the .md file and we found
patterns (rs6000.md ) like

;; Largetoc support
(define_insn "*largetoc_high"
[(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
(high:DI
(unspec [(match_operand:DI 1 "" "")
(match_operand:DI 2 "gpc_reg_operand" "b")]
UNSPEC_TOCREL)))]
"TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
"addis %0,%2,%***@toc@ha")

(define_insn "*largetoc_high_aix<mode>"
[(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
(high:P
(unspec [(match_operand:P 1 "" "")
(match_operand:P 2 "gpc_reg_operand" "b")]
UNSPEC_TOCREL)))]
"TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
"addis %0,%***@u(%2)")

the above patterns answered the difference b/w windows and linux .

Questions to the expert is that using the medium code model ,how we
can get the same linux semantics on windows (without source code
changes) ?

or above distinguish patterns for a reason and which we are missing here ?

Thank you and awaiting for any comments
~Umesh
Umesh Kalappa
2018-10-26 06:52:37 UTC
Permalink
Cced maintainer like David Edelsohn and Segher Boessenkool .

Any suggestions/comments for the below query ?
Thank you
~Umesh
Post by Umesh Kalappa
Hi All,
For the below code (test.c)
int foo()
{
printf("Hello World");
}
ccpc -mcpu=e6500 -mno-altivec -mabi=no-altivec -D_WRS_HARDWARE_FP
-mabi=elfv2 -mcmodel=med -mhard-float -S test.c
the constant string fetched like
where offset signed 32 bit used relatively to toc base on linux as
expected for the medium code model .
R_PPC64_TOC16_HA and R_PPC64_TOC16_LO
same command and windows asm looks like
where offset used signed 16 bit used relatively to toc base why it so ?.
R_PPC64_TOC16 (signed 16 bit offset )
why this difference and when we greping the .md file and we found
patterns (rs6000.md ) like
;; Largetoc support
(define_insn "*largetoc_high"
[(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
(high:DI
(unspec [(match_operand:DI 1 "" "")
(match_operand:DI 2 "gpc_reg_operand" "b")]
UNSPEC_TOCREL)))]
"TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
(define_insn "*largetoc_high_aix<mode>"
[(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
(high:P
(unspec [(match_operand:P 1 "" "")
(match_operand:P 2 "gpc_reg_operand" "b")]
UNSPEC_TOCREL)))]
"TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
the above patterns answered the difference b/w windows and linux .
Questions to the expert is that using the medium code model ,how we
can get the same linux semantics on windows (without source code
changes) ?
or above distinguish patterns for a reason and which we are missing here ?
Thank you and awaiting for any comments
~Umesh
Segher Boessenkool
2018-10-26 14:07:51 UTC
Permalink
Hi Umesh,
Post by Umesh Kalappa
Cced maintainer like David Edelsohn and Segher Boessenkool .
I did see the mail, even started writing a reply, but I got lost in it.
Post by Umesh Kalappa
Any suggestions/comments for the below query ?
No, I have no idea what it means even. What is "Windows"? I would think
you mean the microsoft thing, but there hasn't been a Power port for that
for ages, and none for ELFv2 ever, as far as I know.
Post by Umesh Kalappa
Post by Umesh Kalappa
ccpc -mcpu=e6500 -mno-altivec -mabi=no-altivec -D_WRS_HARDWARE_FP
-mabi=elfv2 -mcmodel=med -mhard-float -S test.c
"ccpc"? It sounds like you are using some third-party port of GCC. We
have no idea what modifications they did; ask them for support instead?

e6500... I don't think that can run ELFv2. Or if it can, that's an
unusual config. And ELFv2 in BE isn't usual either.

-mcmodel=med... That does not exist ("medium" does though). It's the
default of course, like some of the other options you show.
I don't know where this is coming from. Use -dp to see the pattern names
in the .s file.

You also didn't show the compiler version you use (--version). If it is
not recent, you will want to update; whatever problems you have have a
good chance of being fixed already.


Segher
Umesh Kalappa
2018-10-26 14:26:56 UTC
Permalink
Thank you David for the information.
Are you asking about semantics or syntax? Which source code do you
not want to change?
My bad was not clear in the first go and the questions was why on PE
format the relocation is R_PPC64_TOC16 is generated for global access
and on ELF why its R_PPC64_TOC16_HA and R_PPC64_TOC16_LO is generated
for same global access ? why this difference ?

then irrespective of object file formats ,the RELOCATION should be
same for the given target,right ?

for more info
we are using bintuills (2.29) and we run the assembler like
$as.exe -v -a64 -me6500 -many -mbig -o test.o test.s

lets compiler(gcc) emit the syntax as PE format ,but we need
assembler emit relocations like ELF for mcmodel=medium /large .,is
that possible .

or like you suggested change the compiler to emit the ELF syntax for
global access ?

Thank you again
~Umesh
Hi All,
For the below code (test.c)
int foo()
{
printf("Hello World");
}
ccpc -mcpu=e6500 -mno-altivec -mabi=no-altivec -D_WRS_HARDWARE_FP
-mabi=elfv2 -mcmodel=med -mhard-float -S test.c
the constant string fetched like
where offset signed 32 bit used relatively to toc base on linux as
expected for the medium code model .
R_PPC64_TOC16_HA and R_PPC64_TOC16_LO
same command and windows asm looks like
where offset used signed 16 bit used relatively to toc base why it so ?.
R_PPC64_TOC16 (signed 16 bit offset )
why this difference and when we greping the .md file and we found
patterns (rs6000.md ) like
;; Largetoc support
(define_insn "*largetoc_high"
[(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
(high:DI
(unspec [(match_operand:DI 1 "" "")
(match_operand:DI 2 "gpc_reg_operand" "b")]
UNSPEC_TOCREL)))]
"TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
(define_insn "*largetoc_high_aix<mode>"
[(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
(high:P
(unspec [(match_operand:P 1 "" "")
(match_operand:P 2 "gpc_reg_operand" "b")]
UNSPEC_TOCREL)))]
"TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
the above patterns answered the difference b/w windows and linux .
Questions to the expert is that using the medium code model ,how we
can get the same linux semantics on windows (without source code
changes) ?
or above distinguish patterns for a reason and which we are missing here ?
Linux uses the ELF file format and assembler syntax. AIX uses the AIX
file format and assembler syntax.
Windows uses PE file format and syntax, which is not supported in the
rs6000 or powerpcspe ports.
Are you asking about semantics or syntax? Which source code do you
not want to change? If you want to target PE assembler, GCC needs to
be taught about that syntax, or at least it needs to generate the ELF
syntax for Windows PE.
Thanks, David
Loading...