This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
freebsd-aout and _GLOBAL_OFFSET_TABLE_
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: 30 Mar 2002 06:26:04 -0300
- Subject: freebsd-aout and _GLOBAL_OFFSET_TABLE_
- Organization: GCC Team, Red Hat
FreeBSD 2's assembler and linker take _GLOBAL_OFFSET_TABLE_ as a
special symbol. The problem is that FreeBSD a.out prefixes symbol
names with underscores, but this particular symbol must not be
prefixed with an underscore, even though this means a user-defined
GLOBAL_OFFSET_TABLE_ symbol will conflict with it.
Not emitting _GLOBAL_OFFSET_TABLE_ properly has been causing (almost?)
all tests that involve linking to fail on FreeBSD 2.2. This patch
corrects this behavior, such that we emit _GLOBAL_OFFSET_TABLE_ as
intended. Perhaps I'm just overdoing this and I should go with
*_GLOBAL_OFFSET_TABLE_ when creating symbol_refs and lose the %U
before it? If so, ok to install the proposed change? Otherwise, ok
to install this patch? Verified to generate correct PIC on
athlon-pc-linux-gnu and i386-freebsd2.2.7; completing bootstrap as I
write this.
Index: gcc/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
* config/i386/i386.h (GLOBAL_OFFSET_TABLE_SYMBOL_NAME): New.
* config/i386/freebsd-aout.h: Override it.
* config/i386/i386.c (load_pic_register): Use it.
(ix86_output_addr_diff_elt): Likewise.
* config/i386/unix.h (ASM_OUTPUT_MI_THUNK): Likewise.
Index: gcc/config/i386/freebsd-aout.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/freebsd-aout.h,v
retrieving revision 1.8
diff -u -p -r1.8 freebsd-aout.h
--- gcc/config/i386/freebsd-aout.h 2002/01/23 00:56:28 1.8
+++ gcc/config/i386/freebsd-aout.h 2002/03/30 08:26:03
@@ -240,3 +240,7 @@ do {
/* FreeBSD 2.2.7's assembler does not support .quad properly. Do not
use it. */
#undef ASM_QUAD
+
+/* We don't want this to be prefixed by an additional underscore. */
+#undef GLOBAL_OFFSET_TABLE_SYMBOL_NAME
+#define GLOBAL_OFFSET_TABLE_SYMBOL_NAME "*_GLOBAL_OFFSET_TABLE_"
Index: gcc/config/i386/i386.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386.c,v
retrieving revision 1.379
diff -u -p -r1.379 i386.c
--- gcc/config/i386/i386.c 2002/03/29 08:43:18 1.379
+++ gcc/config/i386/i386.c 2002/03/30 08:26:09
@@ -3842,7 +3842,7 @@ load_pic_register ()
if (TARGET_64BIT)
abort ();
- gotsym = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
+ gotsym = gen_rtx_SYMBOL_REF (Pmode, GLOBAL_OFFSET_TABLE_SYMBOL_NAME);
if (TARGET_DEEP_BRANCH_PREDICTION)
{
@@ -6656,9 +6656,12 @@ ix86_output_addr_diff_elt (file, value,
ASM_LONG, LPREFIX, value, LPREFIX, rel);
else if (HAVE_AS_GOTOFF_IN_DATA)
fprintf (file, "%s%s%d@GOTOFF\n", ASM_LONG, LPREFIX, value);
- else
- asm_fprintf (file, "%s%U_GLOBAL_OFFSET_TABLE_+[.-%s%d]\n",
- ASM_LONG, LPREFIX, value);
+ else if (GLOBAL_OFFSET_TABLE_SYMBOL_NAME[0] == '*')
+ asm_fprintf (file, "%s%s+[.-%s%d]\n",
+ ASM_LONG, GLOBAL_OFFSET_TABLE_SYMBOL_NAME+1, LPREFIX, value);
+ else
+ asm_fprintf (file, "%s%U%s+[.-%s%d]\n",
+ ASM_LONG, GLOBAL_OFFSET_TABLE_SYMBOL_NAME, LPREFIX, value);
}
/* Generate either "mov $0, reg" or "xor reg, reg", as appropriate
Index: gcc/config/i386/i386.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386.h,v
retrieving revision 1.252
diff -u -p -r1.252 i386.h
--- gcc/config/i386/i386.h 2002/03/13 05:42:35 1.252
+++ gcc/config/i386/i386.h 2002/03/30 08:26:12
@@ -1910,6 +1910,10 @@ do { \
#define MAX_REGS_PER_ADDRESS 2
+#ifndef GLOBAL_OFFSET_TABLE_SYMBOL_NAME
+#define GLOBAL_OFFSET_TABLE_SYMBOL_NAME "_GLOBAL_OFFSET_TABLE_"
+#endif
+
#define CONSTANT_ADDRESS_P(X) \
(GET_CODE (X) == LABEL_REF || GET_CODE (X) == SYMBOL_REF \
|| GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST \
Index: gcc/config/i386/unix.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/unix.h,v
retrieving revision 1.19
diff -u -p -r1.19 unix.h
--- gcc/config/i386/unix.h 2001/09/21 12:55:18 1.19
+++ gcc/config/i386/unix.h 2002/03/30 08:26:12
@@ -1,5 +1,6 @@
/* Definitions for Unix assembler syntax for the Intel 80386.
- Copyright (C) 1988, 1994, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1988, 1994, 1999, 2000, 2001, 2002
+ Free Software Foundation, Inc.
This file is part of GNU CC.
@@ -105,7 +106,7 @@ do { \
{ \
xops[0] = pic_offset_table_rtx; \
xops[1] = gen_label_rtx (); \
- xops[2] = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_"); \
+ xops[2] = gen_rtx_SYMBOL_REF (Pmode, GLOBAL_OFFSET_TABLE_SYMBOL_NAME);\
\
if (ix86_regparm > 2) \
abort (); \
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist Professional serial bug killer