change the way gcc's collect2 works to fix #74

GCC's AIX port, which RetroPPC is based on, uses a different method
from most other platforms to collect the list of all global constructors
and the list of all exception handling tables.
The "standard" method does not work on AIX because IBM's linker will
discard those symbols too early for GCC's liking if they are not
directly referenced.

Unfortunately, the workaround seems to keep too much, so PPC C++
exececutables were at least 1.1MB big.

We don't need to be compatible with IBM's linker. Instead, hack binutils
to keep the symbols that we need kept, and allow GCC to use the
"standard" method for the collect2 pass.

PowerPC application sizes are now down to a reasonable size.
This commit is contained in:
Wolfgang Thaller 2019-01-13 22:33:07 +01:00
parent 8d303a9185
commit 2999ed8613
2 changed files with 30 additions and 2 deletions

View File

@ -1792,6 +1792,12 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
}
csect = section;
value = sym.n_value - csect->vma;
// RetroPPC: keep constructors & exception tables
if(strncmp(name, "_GLOBAL__", 9) == 0)
{
csect->flags |= SEC_KEEP;
}
}
break;
@ -3764,6 +3770,20 @@ bfd_xcoff_size_dynamic_sections (bfd *output_bfd,
if (info->fini_function != NULL
&& !xcoff_mark_symbol_by_name (info, info->fini_function, 0))
goto error_return;
// RetroPPC: mark sections with SEC_KEEP flag set
for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
{
asection *o;
for (o = sub->sections; o != NULL; o = o->next)
{
if (o->flags & SEC_KEEP)
xcoff_mark(info, o);
}
}
if (auto_export_flags != 0)
{
xcoff_link_hash_traverse (xcoff_hash_table (info),

View File

@ -204,8 +204,16 @@
#define PTRDIFF_TYPE "long int"
/* The AIX linker will discard static constructors in object files before
collect has a chance to see them, so scan the object files directly. */
#define COLLECT_EXPORT_LIST
collect has a chance to see them, so collect2 contains functionality
to scan the object files directly, enabled by:
#define COLLECT_EXPORT_LIST
However, this seems to find all constructors and exception frame tables,
and thus leads to huge executables.
As we don't need to be compatible with the AIX linker, binutils had been
made to not discard these symbols any more *if* the corresponding object
file is loaded.
*/
/* Select a format to encode pointers in exception handling data. CODE
is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is