-mcmodel=large doesn't work to me

2010-10-21 Thread Wei Li
Hi,

I am working on huge object files and I am glad to see that gcc
supports -mcmodel=large now. However, my experiment even doesn't work
because of relocation problem in crtbeginS.o

My Source file: t.c
#include stdio.h
extern int foo(int argc, char **argv);
void *pv1[1024]={(void*)foo,};
char a[2147483658] = {1, 2 };
char b[2147483658] = {2, 3 };
void *pv2[1024]={(void*)foo,};

int foo(int argc, char **argv)
{

    printf(%d, a[2147483657]);
    printf(%d, b[2147483657]);

    return 0;
}

Command line:
gcc -mcmodel=large -fPIC -shared t.c -o t.so

Error:
/gcc4.5.1/lib/gcc/x86_64-unknown-linux-gnu/4.5.1/crtbeginS.o: In
function `__do_global_dtors_aux':
crtstuff.c:(.text+0x3): relocation truncated to fit: R_X86_64_PC32
against `.bss'
crtstuff.c:(.text+0x37): relocation truncated to fit: R_X86_64_PC32
against `.bss'
crtstuff.c:(.text+0x57): relocation truncated to fit: R_X86_64_PC32
against `.bss'
crtstuff.c:(.text+0x62): relocation truncated to fit: R_X86_64_PC32
against `.bss'
crtstuff.c:(.text+0x6d): relocation truncated to fit: R_X86_64_PC32
against `.bss'


Could someone help me figure out the problem? I am using RH5 64bit.

Thanks,
Wei


Re: -mcmodel=large doesn't work to me

2010-10-21 Thread Ian Lance Taylor
Wei Li liwe...@gmail.com writes:

 I am working on huge object files and I am glad to see that gcc
 supports -mcmodel=large now. However, my experiment even doesn't work
 because of relocation problem in crtbeginS.o

This message was not appropriate for the mailing list gcc@gcc.gnu.org,
which is for the development of gcc itself.  It would be appropriate for
the mailing list gcc-h...@gcc.gnu.org.  Please take any followups to
gcc-help.  Thanks.


Basically, you have encountered a problem which is a cross between a bug
and an installation issue.  In order to use -mcmodel=large reliably, you
really need to compile everything with -mcmodel=large.  In this case,
the startup file crtbeginS.o, which is part of gcc, was not compiled
with -mcmodel=large.

This can be fixed with a minor gcc source code modification, but the
effect will be to build -mcmodel=large versions of all the gcc
libraries.  Distros may prefer to avoid that.

So the best approach here may be to add yet another configure option to
request that this be done.  Please consider filing an enhancement
request at http://gcc.gnu.org/bugzilla/ .  Thanks.

Ian