Setting up of GP in static, non-PIC version of glibc?
I compiled a static, non-PIC version of glibc (from H.J's miniport SRPM) to allow testing of MIPS16[e] apps.
One of the things that did not work, is that nobody sets up GP correctly in this case.
Modifying "/usr/src/redhat/BUILD/glibc-2.2.4/sysdeps/mips/elf/start.S" to setup GP:
.text
.globl ENTRY_POINT
.type ENTRY_POINT,@functionENTRY_POINT:
#ifdef __PIC__
SET_GP
#else
la $28, _gp#endif
Makes things work (this code ends in crt1.o). Is this the right place to fix it?
/Hartvig
Quoted 11 lines · Hartvig Ekner
.globl
ENTRY_POINT
.type ENTRY_POINT,@functionENTRY_POINT:
#ifdef__PIC__
SET_GP#else la $28, _gp#endif
Makes things work (this code ends in crt1.o). Is this the right place to fix it?
Non-PIC code doesn't use $gp, so any reference to $gp is a bug. Note that we don't support global data optimization for ELF either that is, -G 0 is the default.
Ralf
Quoted 7 lines · Ralf Baechle
Quoted 2 lines · Johannes Stezenbach
BTW: Who is "we"? Do you mean global data optimization is broken in gcc/binutils or just that no one at SGI is using it?
It's an ECOFF specific optimization that just has been forward ported into the ELF world. And what does this have to do with SGI anyway?
I still don't get it. Why would one not use GP optimization with non-shared non-PIC code? It certainly is used throughout in the non-Linux MIPS world, and on the limited testing I did today it also worked fine. Is there something which is known not to work, or some conflict somewhere which prevents the general use of GP?
/Hartvig
Quoted 11 lines · Ralf Baechle
Quoted 9 lines · Hartvig Ekner
.globl
ENTRY_POINT
.type ENTRY_POINT,@functionENTRY_POINT:
#ifdef__PIC__
SET_GP#else la $28, _gp#endif
Quoted 6 lines
Quoted 2 lines
Makes things work (this code ends in crt1.o). Is this the right place to fix it?
Non-PIC code doesn't use $gp, so any reference to $gp is a bug. Note that we don't support global data optimization for ELF either that is, -G 0 is the default.
I recently experimented with dietlibc and tried to create static, non-PIC binaries, with some success. Contradicting the docs (gcc info), -G 0 is not the default but has to be passed explicitely (even when using the GNU assembler).
BTW: Who is "we"? Do you mean global data optimization is broken in gcc/binutils or just that no one at SGI is using it?
Regards,
Johannes
Quoted 9 lines · Johannes Stezenbach
Quoted 4 lines
Non-PIC code doesn't use $gp, so any reference to $gp is a bug. Note that we don't support global data optimization for ELF either that is, -G 0 is the default.
I recently experimented with dietlibc and tried to create static, non-PIC binaries, with some success. Contradicting the docs (gcc info), -G 0 is not the default but has to be passed explicitely (even when using the GNU assembler).
It always was until somebody broke gcc.
Quoted 2 lines
BTW: Who is "we"? Do you mean global data optimization is broken in gcc/binutils or just that no one at SGI is using it?
It's an ECOFF specific optimization that just has been forward ported into the ELF world. And what does this have to do with SGI anyway?
Ralf
Quoted 6 lines · Ralf Baechle
Quoted 2 lines · Johannes Stezenbach
BTW: Who is "we"? Do you mean global data optimization is broken in gcc/binutils or just that no one at SGI is using it?
It's an ECOFF specific optimization that just has been forward ported into the ELF world. And what does this have to do with SGI anyway?
I was wondering who you speak for when you say "we don't support foobar", and your email is @oss.sgi.com.
I was just trying to decode the meaning of what you said. Like, did you mean "I don't care about it" or "The tools are totally broken and you have to go along way to use it"?
The global data optimization would fit dietlibc's goal of as-small-as-possible, statically linked binaries. But from what you said I gather I would have to fix gcc and binutils first.
Johannes
Quoted 11 lines · Hartvig Ekner
Quoted 5 lines
Quoted 2 lines
BTW: Who is "we"? Do you mean global data optimization is broken in gcc/binutils or just that no one at SGI is using it?
It's an ECOFF specific optimization that just has been forward ported into the ELF world. And what does this have to do with SGI anyway?
I still don't get it. Why would one not use GP optimization with non-shared non-PIC code? It certainly is used throughout in the non-Linux MIPS world, and on the limited testing I did today it also worked fine. Is there something which is known not to work, or some conflict somewhere which prevents the general use of GP?
I thought gcc would would for no good reason plain refuse to use global pointer optimization with ELF - but I was wrong, just tested it again. I also noticed that older gcc would emit initialized data to .data with -G even though small data should go to .sdata.
Won't work by just enabeling for the kernel though. The kernel has it's own idea of how to use the $gp register.
Ralf
Quoted 5 lines · Johannes Stezenbach
Quoted 2 lines
It's an ECOFF specific optimization that just has been forward ported into the ELF world. And what does this have to do with SGI anyway?
I was wondering who you speak for when you say "we don't support foobar", and your email is @oss.sgi.com.
You seem to be unaware that half of oss users are ex-sgi employees :-)
Quoted 8 lines
I was just trying to decode the meaning of what you said. Like, did you mean "I don't care about it" or "The tools are totally broken and you have to go along way to use it"?
The global data optimization would fit dietlibc's goal of as-small-as-possible, statically linked binaries. But from what you said I gather I would have to fix gcc and binutils first.
See also my other email about the status of -G.
Ralf
Quoted 11 lines · Ralf Baechle
Quoted 9 lines · Hartvig Ekner
.globl
ENTRY_POINT
.type ENTRY_POINT,@functionENTRY_POINT:
#ifdef__PIC__
SET_GP#else la $28, _gp#endif
Quoted 6 lines
Quoted 2 lines
Makes things work (this code ends in crt1.o). Is this the right place to fix it?
Non-PIC code doesn't use $gp, so any reference to $gp is a bug. Note that we don't support global data optimization for ELF either that is, -G 0 is the default.
By default non-PIC code *does* use $gp due to the brain damage in gas; gas defaults to -G 8 unless told otherwise (-KPIC implies -G0 so we don't see this in PIC code.) gcc won't know anything about this, of course.
What I'm doing in SUBTARGET_ASM_SPEC is to write something like "%{fno-pic: %{!G: -G0}}"--if we're not in PIC mode, pass -G0 to gas by default.
Anyway, once that's straightened out, -G8 does appear to work the way you'd expect, with the code that Hartvig pasted above---I had written a byte-for-byte identical patch :-)
Jay
Quoted 5 lines · Jay Carlson
By default non-PIC code *does* use $gp due to the brain damage in gas; gas defaults to -G 8 unless told otherwise (-KPIC implies -G0 so we don't see this in PIC code.) gcc won't know anything about this, of course.
Quoted 7 lines
What I'm doing in
SUBTARGET_ASM_SPECis to write something like "%{fno-pic: %{!G: -G0}}"--if we're not in PIC mode, pass -G0 to gas by default.Anyway, once that's straightened out, -G8 does appear to work the way you'd expect, with the code that Hartvig pasted above---I had written a byte-for-byte identical patch :-)
I agree on that one except that 64kB of small data no longer seem to be sufficient for every common application in the world. So I'd vote for a more defensive choice of the -G value, that is 0.
Ralf
Quoted 11 lines · Ralf Baechle
Quoted 9 lines · Jay Carlson
By default non-PIC code *does* use $gp due to the brain damage in gas; gas defaults to -G 8 unless told otherwise (-KPIC implies -G0 so we don't see this in PIC code.) gcc won't know anything about this, of course.
What I'm doing in
SUBTARGET_ASM_SPECis to write something like "%{fno-pic: %{!G: -G0}}"--if we're not in PIC mode, pass -G0 to gas by default.
Quoted 7 lines
Quoted 3 lines
Anyway, once that's straightened out, -G8 does appear to work the way you'd expect, with the code that Hartvig pasted above---I had written a byte-for-byte identical patch :-)
I agree on that one except that 64kB of small data no longer seem to be sufficient for every common application in the world. So I'd vote for a more defensive choice of the -G value, that is 0.
Right. In my ideal world, here's how it would work:
cc1 defaults to -G0. I think we have that now.
gas defaults to -G0. Messing with SUBTARGET_ASM_SPEC has that effect for people who use the gcc driver, but anybody invoking gas directly will still hit this problem, but too bad.
So I think the primary constituency for gas defaulting to -G8 are existing cygnuhhhh I mean redhat embedded MIPS customers, outside of Linux; that's who we should check with before we change the default.
Jay
Quoted 11 lines · Jay Carlson
Right. In my ideal world, here's how it would work:
cc1 defaults to -G0. I think we have that now.
gas defaults to -G0. Messing with
SUBTARGET_ASM_SPEChas that effect for people who use the gcc driver, but anybody invoking gas directly will still hit this problem, but too bad.So I think the primary constituency for gas defaulting to -G8 are existing cygnuhhhh I mean redhat embedded MIPS customers, outside of Linux; that's who we should check with before we change the default.
So far we've been following the MIPS-UNIX tradition more than anything else.
Ralf
Hi,
Quoted 11 lines · Jay Carlson
Right. In my ideal world, here's how it would work:
cc1 defaults to -G0. I think we have that now.
gas defaults to -G0. Messing with
SUBTARGET_ASM_SPEChas that effect for people who use the gcc driver, but anybody invoking gas directly will still hit this problem, but too bad.So I think the primary constituency for gas defaulting to -G8 are existing cygnuhhhh I mean redhat embedded MIPS customers, outside of Linux; that's who we should check with before we change the default.
We cannot change the default for non-Linux MIPS users without causing massive problems. As far as I know, everybody uses -G8 as the default, which can include such things as libraries (which may be delivered as binary only).
So this is probably one of these things where the Linux/MIPS world will do one thing, and the rest something else.
/Hartvig