Bug 38988 - Cannot build crtstuff.c with -mcmodel=large -fPIC -O2
Summary: Cannot build crtstuff.c with -mcmodel=large -fPIC -O2
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.3.4
Assignee: Uroš Bizjak
URL:
Keywords:
: 39296 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-01-27 17:15 UTC by Steve Ellcey
Modified: 2009-02-25 01:47 UTC (History)
4 users (show)

See Also:
Host:
Target: x86_64-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Patch to fix crtstuff.c failure (688 bytes, patch)
2009-01-27 19:55 UTC, Uroš Bizjak
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Ellcey 2009-01-27 17:15:34 UTC
If you compile the following code (cut down from crtstuff.c) with -mcmodel=large -fPIC -O2 on a 64 bit x86 target GCC will ICE.  There are at least two problems, one in cselib_hash_rtx, and if that is fixed then I get a shared rtx abort.

The test case is 

        typedef long unsigned int size_t;
        typedef void (*func_ptr) (void);
        static func_ptr __DTOR_LIST__[1] = { (func_ptr) (-1) };
        static void __attribute__((used)) __do_global_dtors_aux (void)
        {
          extern func_ptr __DTOR_END__[];
          size_t dtor_idx = 0;
          const size_t max_idx = __DTOR_END__ - __DTOR_LIST__ - 1;
          func_ptr f;
          while (dtor_idx < max_idx)
          {
            f = __DTOR_LIST__[++dtor_idx];
            f ();
          }
        }
Comment 1 H.J. Lu 2009-01-27 17:46:21 UTC
Do you have a testcase to show that -mcmodel=large doesn't work for
you?
Comment 2 H.J. Lu 2009-01-27 17:48:36 UTC
By testcase, I meant a user application, not crtstuff.c, like

# gcc -mcmodel=large foo.c
# ./a.out
Comment 3 Steve Ellcey 2009-01-27 17:54:48 UTC
No, I don't have a user application.  I believe the problem was that the user was compiling a program with something like -Wl,--section-start,.text=0x110000000 and because the crt files weren't compiled with -mcmodel=large they couldn't reach the text section.  If I compile a simple hello world program with this linker option I get a number of errors about relocations being truncated.
Comment 4 H.J. Lu 2009-01-27 18:07:08 UTC
Assuming you have solved crtstuff.c issue, will /usr/lib64/crt1.o
work with -Wl,--section-start,.text=0x110000000? Can you try
the latest binutils from CVS with

[hjl@gnu-6 pr38988]$ cat f.c
#include <stdio.h>

int
main ()
{
  printf ("hello\n");
  return 0;
}
[hjl@gnu-6 pr38988]$ gcc f.c -Wl,-Ttext-segment,0x110000000 -fpie -pie -g
[hjl@gnu-6 pr38988]$ gdb a.out 
GNU gdb (GDB) 6.8.50.20081208-cvs (AVX revision 4683)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
(gdb) b main
Breakpoint 1 at 0x110000708: file f.c, line 6.
(gdb) r
Starting program: /export/home/hjl/bugs/gcc/pr38988/a.out 

Breakpoint 1, main () at f.c:6
6	  printf ("hello\n");
(gdb) p $rip
$1 = (void (*)()) 0x110000708 <main+4>
(gdb) c
Continuing.
hello

Program exited normally.
(gdb) 

I added a new linker switch:

-Ttext-segment ADDRESS      Set address of text segment

It may work for you.
Comment 5 Uroš Bizjak 2009-01-27 19:55:05 UTC
Created attachment 17195 [details]
Patch to fix crtstuff.c failure

This patch fixes crtstuff failure with -mcmodel=large.
Comment 6 Uroš Bizjak 2009-01-27 19:57:00 UTC
Steve, can you test this patch if it fixes your bootstrap?
Comment 7 Steve Ellcey 2009-01-27 20:03:36 UTC
Did you change cselib_hash_rtx too?  I don't see that change in your patch but I know I need it to get to the shared rtx bug that your patch will hopefully fix.
Comment 8 Uroš Bizjak 2009-01-27 20:28:13 UTC
(In reply to comment #7)
> Did you change cselib_hash_rtx too?  I don't see that change in your patch but
> I know I need it to get to the shared rtx bug that your patch will hopefully
> fix.

The fix is not necessary, since we now pass correct RTX to hash function.

IOW, the patch as attached is complete and fixes test from comment #0.

Comment 9 Steve Ellcey 2009-01-27 23:45:36 UTC
Yes, your patch does fix my problem.
Comment 10 uros 2009-01-28 07:58:30 UTC
Subject: Bug 38988

Author: uros
Date: Wed Jan 28 07:58:07 2009
New Revision: 143720

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143720
Log:
	PR target/38988
	* config/i386/i386.md (set_rip_rex64): Wrap operand 1 in label_ref.
	(set_got_offset_rex64): Ditto.


Added:
    trunk/gcc/testsuite/gcc.target/i386/pr38988.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.md

Comment 11 uros 2009-01-29 10:05:31 UTC
Subject: Bug 38988

Author: uros
Date: Thu Jan 29 10:05:17 2009
New Revision: 143752

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143752
Log:
	Backport from mainline:
	2009-01-28  Uros Bizjak  <ubizjak@gmail.com>

	PR target/38988
	* gcc.target/i386/pr38988.c: New test.

	2009-01-27  Uros Bizjak  <ubizjak@gmail.com>

	PR middle-end/38969
	* gcc.c-torture/execute/pr38969.c: New test.

testsuite/ChangeLog:

	Backport from mainline:
	2009-01-28  Uros Bizjak  <ubizjak@gmail.com>

	PR target/38988
	* config/i386/i386.md (set_rip_rex64): Wrap operand 1 in label_ref.
	(set_got_offset_rex64): Ditto.

	2009-01-27  Uros Bizjak  <ubizjak@gmail.com>

	PR middle-end/38969
	* calls.c (initialize_argument_information): Do not wrap complex
	arguments in SAVE_EXPR.


Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/execute/pr38969.c
      - copied unchanged from r143699, trunk/gcc/testsuite/gcc.c-torture/execute/pr38969.c
    branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/pr38988.c
      - copied unchanged from r143720, trunk/gcc/testsuite/gcc.target/i386/pr38988.c
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/calls.c
    branches/gcc-4_3-branch/gcc/config/i386/i386.md
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 12 Uroš Bizjak 2009-01-29 10:09:19 UTC
Fixed.
Comment 13 H.J. Lu 2009-02-25 01:47:44 UTC
*** Bug 39296 has been marked as a duplicate of this bug. ***