Re: Power 64 ELFv2 w.r.t toc(cmodel=medium) on windows.

2018-10-26 Thread David Edelsohn
On Fri, Oct 26, 2018 at 10:27 AM Umesh Kalappa  wrote:
>
> 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 ?

Relocations are specific to ABIs.  In the medium code model, the ELF
ABI allows a 32 bit offset relative to the TOC (high and low parts).
AIX does not support medium code model of 32 bit data offset from TOC,
it only provides the larger TOC offset inserted by the linker.

There is no support in the rs6000 backend for PE file format and ABI.
Your "Windows" build is adopting whatever configuration bits fall out
when ELF and AIX are not specified.

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

No.  Relocations are specific to each ABI.

>
> 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 ?

I don't know about Windows and PE.  I doubt that adjusting GCC to
behave more like ELF or more like AIX will magically fix your Windows
PE configuration.

I have no idea where you obtained the toolchain and what "ccpc" means.
If it's your toolchain, you need to debug it and add the appropriate
PE support.  If you received it from a vendor, you need to ask the
vendor.

Thanks, DAvid

>
> Thank you again
> ~Umesh
>
>
> On Fri, Oct 26, 2018 at 6:57 PM David Edelsohn  wrote:
> >
> > On Thu, Oct 25, 2018 at 11:53 AM Umesh Kalappa  
> > wrote:
> > >
> > > 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,.LC0@toc@ha
> > >  addi 3,3,.LC0@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,.LC0@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,%1@toc@ha")
> > >
> > > (define_insn "*largetoc_high_aix"
> > >   [(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,%1@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  ?
> >
> > 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


Re: Power 64 ELFv2 w.r.t toc(cmodel=medium) on windows.

2018-10-26 Thread Umesh Kalappa
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


On Fri, Oct 26, 2018 at 6:57 PM David Edelsohn  wrote:
>
> On Thu, Oct 25, 2018 at 11:53 AM Umesh Kalappa  
> wrote:
> >
> > 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,.LC0@toc@ha
> >  addi 3,3,.LC0@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,.LC0@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,%1@toc@ha")
> >
> > (define_insn "*largetoc_high_aix"
> >   [(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,%1@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  
> > ?
>
> 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


Re: Power 64 ELFv2 w.r.t toc(cmodel=medium) on windows.

2018-10-26 Thread Segher Boessenkool
Hi Umesh,

On Fri, Oct 26, 2018 at 12:22:37PM +0530, Umesh Kalappa wrote:
> Cced maintainer like David Edelsohn and Segher Boessenkool .

I did see the mail, even started writing a reply, but I got lost in it.

> 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.

More problems:

> > 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.

> > la 3,.LC0@toc(2)

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


Re: Power 64 ELFv2 w.r.t toc(cmodel=medium) on windows.

2018-10-26 Thread David Edelsohn
On Thu, Oct 25, 2018 at 11:53 AM Umesh Kalappa  wrote:
>
> 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,.LC0@toc@ha
>  addi 3,3,.LC0@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,.LC0@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,%1@toc@ha")
>
> (define_insn "*largetoc_high_aix"
>   [(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,%1@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  ?

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


Re: Power 64 ELFv2 w.r.t toc(cmodel=medium) on windows.

2018-10-26 Thread Umesh Kalappa
Cced maintainer like David Edelsohn and Segher Boessenkool .

Any suggestions/comments for the below query ?
Thank you
~Umesh
On Thu, Oct 25, 2018 at 9:23 PM Umesh Kalappa  wrote:
>
> 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,.LC0@toc@ha
>  addi 3,3,.LC0@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,.LC0@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,%1@toc@ha")
>
> (define_insn "*largetoc_high_aix"
>   [(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,%1@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