diff --git a/binutils/bfd/xcofflink.c b/binutils/bfd/xcofflink.c index 2504b226f6..f27ab3fcec 100644 --- a/binutils/bfd/xcofflink.c +++ b/binutils/bfd/xcofflink.c @@ -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), diff --git a/gcc/gcc/config/rs6000/macos.h b/gcc/gcc/config/rs6000/macos.h index bdd26ffea8..6b79262dc8 100644 --- a/gcc/gcc/config/rs6000/macos.h +++ b/gcc/gcc/config/rs6000/macos.h @@ -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