AIX collect2.c and longlong.h fix
David Edelsohn
dje@watson.ibm.com
Mon Aug 14 13:56:00 GMT 2000
Among the improvements made to collect2.c for AIX in 1998-99,
libgcc.a symbols were implicitly imported from the main program when
creating a shared object. This essentially treats the main program as a
shared library -- a preview of the libgcc.so proposal. Unfortunately this
particular implementation creates a dependency on the symbols in the main
program which will not be satisfied if the main program was not compiled
by GCC or if the main program does not require all of the symbols needed
by the shared object (e.g., gcc versus g++). This patch removes the
symbol import feature allowing GCC to create stand-alone shared objects
but reverting those shared objects to split EH frame tables until the
general libgcc.so fix is implemented.
A second, minor patch fixes an AIX architecture test in longlong.h.
David
* collect2.c: Remove use of AIX import file.
* longlong.h: Test ARCH_PWR not ARCH_POWER.
Index: longlong.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/longlong.h,v
retrieving revision 1.20
diff -c -p -r1.20 longlong.h
*** longlong.h 2000/05/29 07:52:24 1.20
--- longlong.h 2000/08/14 20:41:22
*************** UDItype __umulsidi3 (USItype, USItype);
*** 865,871 ****
} while (0)
#define SMUL_TIME 14
#define UDIV_TIME 120
! #elif defined (_ARCH_POWER)
#define umul_ppmm(xh, xl, m0, m1) \
do { \
USItype __m0 = (m0), __m1 = (m1); \
--- 865,871 ----
} while (0)
#define SMUL_TIME 14
#define UDIV_TIME 120
! #elif defined (_ARCH_PWR)
#define umul_ppmm(xh, xl, m0, m1) \
do { \
USItype __m0 = (m0), __m1 = (m1); \
Index: collect2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/collect2.c,v
retrieving revision 1.98
diff -c -p -r1.98 collect2.c
*** collect2.c 2000/07/22 23:29:13 1.98
--- collect2.c 2000/08/14 20:26:22
*************** static const char *c_file; /* <xxx>.c f
*** 202,208 ****
static const char *o_file; /* <xxx>.o for constructor/destructor list. */
#ifdef COLLECT_EXPORT_LIST
static const char *export_file; /* <xxx>.x for AIX export list. */
- static const char *import_file; /* <xxx>.p for AIX import list. */
#endif
const char *ldout; /* File for ld errors. */
static const char *output_file; /* Output file for ld. */
--- 202,207 ----
*************** static struct head constructors; /* list
*** 218,225 ****
static struct head destructors; /* list of destructors found */
#ifdef COLLECT_EXPORT_LIST
static struct head exports; /* list of exported symbols */
- static struct head imports; /* list of imported symbols */
- static struct head undefined; /* list of undefined symbols */
#endif
static struct head frame_tables; /* list of frame unwind info tables */
--- 217,222 ----
*************** static void scan_libraries PARAMS ((cons
*** 296,302 ****
static int is_in_list PARAMS ((const char *, struct id *));
static void write_aix_file PARAMS ((FILE *, struct id *));
static char *resolve_lib_name PARAMS ((const char *));
- static int use_import_list PARAMS ((const char *));
static int ignore_library PARAMS ((const char *));
#endif
static char *extract_string PARAMS ((const char **));
--- 293,298 ----
*************** collect_exit (status)
*** 338,346 ****
#ifdef COLLECT_EXPORT_LIST
if (export_file != 0 && export_file[0])
maybe_unlink (export_file);
-
- if (import_file != 0 && import_file[0])
- maybe_unlink (import_file);
#endif
if (ldout != 0 && ldout[0])
--- 334,339 ----
*************** handler (signo)
*** 471,479 ****
#ifdef COLLECT_EXPORT_LIST
if (export_file != 0 && export_file[0])
maybe_unlink (export_file);
-
- if (import_file != 0 && import_file[0])
- maybe_unlink (import_file);
#endif
signal (signo, SIG_DFL);
--- 464,469 ----
*************** main (argc, argv)
*** 1073,1079 ****
o_file = make_temp_file (".o");
#ifdef COLLECT_EXPORT_LIST
export_file = make_temp_file (".x");
- import_file = make_temp_file (".p");
#endif
ldout = make_temp_file (".ld");
*c_ptr++ = c_file_name;
--- 1063,1068 ----
*************** main (argc, argv)
*** 1165,1178 ****
/* Resolving full library name. */
const char *s = resolve_lib_name (arg+2);
- /* If we will use an import list for this library,
- we should exclude it from ld args. */
- if (use_import_list (s))
- {
- ld1--;
- ld2--;
- }
-
/* Saving a full library name. */
add_to_list (&libs, s);
}
--- 1154,1159 ----
*************** main (argc, argv)
*** 1243,1256 ****
/* libraries can be specified directly, i.e. without -l flag. */
else
{
- /* If we will use an import list for this library,
- we should exclude it from ld args. */
- if (use_import_list (arg))
- {
- ld1--;
- ld2--;
- }
-
/* Saving a full library name. */
add_to_list (&libs, arg);
}
--- 1224,1229 ----
*************** main (argc, argv)
*** 1281,1294 ****
scan_prog_file (list->name, PASS_FIRST);
}
- if (frame_tables.number > 0 && shared_obj)
- {
- /* If there are any frames, then we will need
- the frame table handling functions. */
- add_to_list (&imports, "__register_frame_info_table");
- add_to_list (&imports, "__deregister_frame_info");
- }
-
if (exports.first)
{
char *buf = xmalloc (strlen (export_file) + 5);
--- 1254,1259 ----
*************** main (argc, argv)
*** 1304,1326 ****
if (fclose (exportf))
fatal_perror ("fclose %s", export_file);
}
-
- if (imports.first)
- {
- char *buf = xmalloc (strlen (import_file) + 5);
-
- sprintf (buf, "-bI:%s", import_file);
- *ld1++ = buf;
- *ld2++ = buf;
-
- importf = fopen (import_file, "w");
- if (importf == (FILE *) 0)
- fatal_perror ("%s", import_file);
- fputs ("#! .\n", importf);
- write_aix_file (importf, imports.first);
- if (fclose (importf))
- fatal_perror ("fclose %s", import_file);
- }
#endif
*c_ptr++ = c_file;
--- 1269,1274 ----
*************** main (argc, argv)
*** 1397,1404 ****
/* But make sure we delete the export file we may have created. */
if (export_file != 0 && export_file[0])
maybe_unlink (export_file);
- if (import_file != 0 && import_file[0])
- maybe_unlink (import_file);
#endif
maybe_unlink (c_file);
maybe_unlink (o_file);
--- 1345,1350 ----
*************** main (argc, argv)
*** 1453,1459 ****
#ifdef COLLECT_EXPORT_LIST
maybe_unlink (export_file);
- maybe_unlink (import_file);
#endif
maybe_unlink (c_file);
maybe_unlink (o_file);
--- 1399,1404 ----
*************** main (argc, argv)
*** 1555,1561 ****
#ifdef COLLECT_EXPORT_LIST
maybe_unlink (export_file);
- maybe_unlink (import_file);
#endif
return 0;
--- 1500,1505 ----
*************** scan_prog_file (prog_name, which_pass)
*** 2747,2756 ****
LDFILE *ldptr = NULL;
int sym_index, sym_count;
int is_shared = 0;
- #ifdef COLLECT_EXPORT_LIST
- /* Should we generate an import list for given prog_name? */
- int import_flag = (which_pass == PASS_OBJ ? 0 : use_import_list (prog_name));
- #endif
if (which_pass != PASS_FIRST && which_pass != PASS_OBJ)
return;
--- 2691,2696 ----
*************** scan_prog_file (prog_name, which_pass)
*** 2815,2827 ****
#ifdef COLLECT_EXPORT_LIST
if (which_pass == PASS_OBJ)
add_to_list (&exports, name);
- /* If this symbol was undefined and we are building
- an import list, we should add a symbol to this
- list. */
- else
- if (import_flag
- && is_in_list (name, undefined.first))
- add_to_list (&imports, name);
#endif
break;
--- 2755,2760 ----
*************** scan_prog_file (prog_name, which_pass)
*** 2831,2843 ****
#ifdef COLLECT_EXPORT_LIST
if (which_pass == PASS_OBJ)
add_to_list (&exports, name);
- /* If this symbol was undefined and we are building
- an import list, we should add a symbol to this
- list. */
- else
- if (import_flag
- && is_in_list (name, undefined.first))
- add_to_list (&imports, name);
#endif
break;
--- 2764,2769 ----
*************** scan_prog_file (prog_name, which_pass)
*** 2863,2895 ****
#ifdef COLLECT_EXPORT_LIST
if (which_pass == PASS_OBJ)
add_to_list (&exports, name);
- /* If we are building an import list, we
- should add the symbol to the list.
- We'd like to do it only if the symbol
- is not defined, but we can't tell
- that here (it is only known whether a symbol
- is referenced and not defined, but who
- would reference an EH table entry?). */
- else
- if (import_flag)
- add_to_list (&imports, name);
#endif
break;
default: /* not a constructor or destructor */
#ifdef COLLECT_EXPORT_LIST
/* If we are building a shared object on AIX we need
! to explicitly export all global symbols or add
! them to import list. */
if (shared_obj)
{
if (which_pass == PASS_OBJ && (! export_flag))
add_to_list (&exports, name);
- else if (! is_shared
- && which_pass == PASS_FIRST
- && import_flag
- && is_in_list(name, undefined.first))
- add_to_list (&imports, name);
}
#endif
continue;
--- 2789,2805 ----
#ifdef COLLECT_EXPORT_LIST
if (which_pass == PASS_OBJ)
add_to_list (&exports, name);
#endif
break;
default: /* not a constructor or destructor */
#ifdef COLLECT_EXPORT_LIST
/* If we are building a shared object on AIX we need
! to explicitly export all global symbols. */
if (shared_obj)
{
if (which_pass == PASS_OBJ && (! export_flag))
add_to_list (&exports, name);
}
#endif
continue;
*************** scan_prog_file (prog_name, which_pass)
*** 2907,2930 ****
symbol.iss, (long) symbol.value, symbol.index, name);
#endif
}
- #ifdef COLLECT_EXPORT_LIST
- /* If we are building a shared object we should collect
- information about undefined symbols for later
- import list generation. */
- else if (shared_obj && GCC_UNDEF_SYMBOL (symbol))
- {
- char *name;
-
- if ((name = ldgetname (ldptr, &symbol)) == NULL)
- continue; /* should never happen */
-
- /* All AIX function names have a duplicate entry
- beginning with a dot. */
- if (*name == '.')
- ++name;
- add_to_list (&undefined, name);
- }
- #endif
}
}
#ifdef COLLECT_EXPORT_LIST
--- 2817,2822 ----
*************** scan_prog_file (prog_name, which_pass)
*** 2954,2977 ****
#ifdef COLLECT_EXPORT_LIST
-
- /* This new function is used to decide whether we should
- generate import list for an object or to use it directly. */
- static int
- use_import_list (prog_name)
- const char *prog_name;
- {
- char *p;
-
- /* If we do not build a shared object then import list should not be used. */
- if (! shared_obj) return 0;
-
- /* Currently we check only for libgcc, but this can be changed in future. */
- p = strstr (prog_name, "libgcc.a");
- if (p != 0 && (strlen (p) == sizeof ("libgcc.a") - 1))
- return 1;
- return 0;
- }
/* Given a library name without "lib" prefix, this function
returns a full library name including a path. */
--- 2846,2851 ----
More information about the Gcc-patches
mailing list