From 5753006bf045fa872b7e7b377b6fe4e299305b69 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 28 Sep 1995 16:36:34 +0000 Subject: [PATCH] * lexsup.c (parse_args): Handle -assert. * emulparams/sun4.sh (GENERATE_SHLIB_SCRIPT): Define. * emultempl/sunos.em (gld${EMULATION_NAME}_get_script): Use the shared library script when appropriate. * scripttempl/aout.sc: If CREATE_SHLIB is set, start the .text section at SIZEOF_HEADERS. --- ld/ChangeLog | 9 ++ ld/emulparams/sun4.sh | 8 ++ ld/emultempl/sunos.em | 6 +- ld/lexsup.c | 215 +++++++++-------------------------------- ld/scripttempl/aout.sc | 14 ++- 5 files changed, 74 insertions(+), 178 deletions(-) create mode 100644 ld/emulparams/sun4.sh diff --git a/ld/ChangeLog b/ld/ChangeLog index 2356ca2ed7c..6bf38d1fbee 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,12 @@ +Thu Sep 28 12:34:13 1995 Ian Lance Taylor + + * lexsup.c (parse_args): Handle -assert. + * emulparams/sun4.sh (GENERATE_SHLIB_SCRIPT): Define. + * emultempl/sunos.em (gld${EMULATION_NAME}_get_script): Use the + shared library script when appropriate. + * scripttempl/aout.sc: If CREATE_SHLIB is set, start the .text + section at SIZEOF_HEADERS. + Thu Sep 28 01:40:37 1995 Doug Evans * Makefile.in (earmcoff.c): Build. diff --git a/ld/emulparams/sun4.sh b/ld/emulparams/sun4.sh new file mode 100644 index 00000000000..5e0387c3caa --- /dev/null +++ b/ld/emulparams/sun4.sh @@ -0,0 +1,8 @@ +SCRIPT_NAME=aout +OUTPUT_FORMAT="a.out-sunos-big" +TEXT_START_ADDR=0x2020 +PAGE_SIZE=0x2000 +NONPAGED_TEXT_START_ADDR=0x2000 +ARCH=sparc +TEMPLATE_NAME=sunos +GENERATE_SHLIB_SCRIPT=yes diff --git a/ld/emultempl/sunos.em b/ld/emultempl/sunos.em index ffdf098e157..fc98092c81a 100644 --- a/ld/emultempl/sunos.em +++ b/ld/emultempl/sunos.em @@ -334,7 +334,7 @@ gld${EMULATION_NAME}_before_allocation () lang_for_each_input_file (gld${EMULATION_NAME}_set_need); - ASSERT (need_pnames - sneed->contents == need_size); + ASSERT ((bfd_size_type) (need_pnames - sneed->contents) == need_size); } if (srules != NULL) @@ -540,6 +540,8 @@ cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c < #include "getopt.h" #include "bfdlink.h" -#include "config.h" #include "ld.h" #include "ldmain.h" #include "ldmisc.h" @@ -34,6 +33,7 @@ the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307 #include "ldlex.h" #include "ldfile.h" #include "ldver.h" +#include "ldemul.h" /* Somewhere above, sys/stat.h got included . . . . */ #if !defined(S_ISDIR) && defined(S_IFDIR) @@ -47,15 +47,6 @@ unsigned long strtoul (); static void set_default_dirlist PARAMS ((char *dirlist_ptr)); static void set_section_start PARAMS ((char *sect, char *valstr)); -/* PE format; declare additional functions */ -static void set_pe_subsystem PARAMS ((void)); -static void set_pe_stack_heap PARAMS ((bfd_link_pe_info_dval *reserve, - bfd_link_pe_info_dval *commit)); -static void set_pe_value PARAMS ((bfd_link_pe_info_dval *val)); - -/* PE info; passed to bfd if any pe options set. */ -static bfd_link_pe_info pe_info; - void parse_args (argc, argv) @@ -64,6 +55,7 @@ parse_args (argc, argv) { int i; int ingroup = 0; + char *default_dirlist = NULL; /* Starting the short option string with '-' is for programs that expect options and other ARGV-elements in any order and that care about @@ -75,13 +67,13 @@ parse_args (argc, argv) /* 150 isn't special; it's just an arbitrary non-ASCII char value. */ -#define OPTION_CALL_SHARED 150 +#define OPTION_ASSERT 150 +#define OPTION_CALL_SHARED (OPTION_ASSERT + 1) #define OPTION_DEFSYM (OPTION_CALL_SHARED + 1) #define OPTION_DYNAMIC_LINKER (OPTION_DEFSYM + 1) #define OPTION_EB (OPTION_DYNAMIC_LINKER + 1) #define OPTION_EL (OPTION_EB + 1) -#define OPTION_HEAP (OPTION_EL + 1) -#define OPTION_EMBEDDED_RELOCS (OPTION_HEAP + 1) +#define OPTION_EMBEDDED_RELOCS (OPTION_EL + 1) #define OPTION_EXPORT_DYNAMIC (OPTION_EMBEDDED_RELOCS + 1) #define OPTION_HELP (OPTION_EXPORT_DYNAMIC + 1) #define OPTION_IGNORE (OPTION_HELP + 1) @@ -112,23 +104,10 @@ parse_args (argc, argv) #define OPTION_SPLIT_BY_FILE (OPTION_SPLIT_BY_RELOC + 1) #define OPTION_WHOLE_ARCHIVE (OPTION_SPLIT_BY_FILE + 1) -/* Used for setting flags in the PE header. */ -#define OPTION_BASE_FILE (OPTION_WHOLE_ARCHIVE + 1) -#define OPTION_DLL (OPTION_BASE_FILE + 1) -#define OPTION_FILE_ALIGNMENT (OPTION_DLL + 1) -#define OPTION_IMAGE_BASE (OPTION_FILE_ALIGNMENT + 1) -#define OPTION_MAJOR_IMAGE_VERSION (OPTION_IMAGE_BASE + 1) -#define OPTION_MAJOR_OS_VERSION (OPTION_MAJOR_IMAGE_VERSION + 1) -#define OPTION_MAJOR_SUBSYSTEM_VERSION (OPTION_MAJOR_OS_VERSION + 1) -#define OPTION_MINOR_IMAGE_VERSION (OPTION_MAJOR_SUBSYSTEM_VERSION + 1) -#define OPTION_MINOR_OS_VERSION (OPTION_MINOR_IMAGE_VERSION + 1) -#define OPTION_MINOR_SUBSYSTEM_VERSION (OPTION_MINOR_OS_VERSION + 1) -#define OPTION_SECTION_ALIGNMENT (OPTION_MINOR_SUBSYSTEM_VERSION + 1) -#define OPTION_STACK (OPTION_SECTION_ALIGNMENT + 1) -#define OPTION_SUBSYSTEM (OPTION_STACK + 1) static struct option longopts[] = { /* Sorted alphabeticaly, except for the PE options grouped at the end. */ + {"assert", required_argument, NULL, OPTION_ASSERT}, {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED}, {"Bstatic", no_argument, NULL, OPTION_NON_SHARED}, {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC}, @@ -179,21 +158,6 @@ parse_args (argc, argv) {"split-by-file", no_argument, NULL, OPTION_SPLIT_BY_FILE}, {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE}, - /* PE options */ - {"base-file", required_argument, NULL, OPTION_BASE_FILE}, - {"dll", no_argument, NULL, OPTION_DLL}, - {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT}, - {"heap", required_argument, NULL, OPTION_HEAP}, - {"image-base", required_argument, NULL, OPTION_IMAGE_BASE}, - {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION}, - {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION}, - {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION}, - {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION}, - {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION}, - {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION}, - {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT}, - {"stack", required_argument, NULL, OPTION_STACK}, - {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM}, {NULL, no_argument, NULL, 0} }; @@ -220,11 +184,15 @@ parse_args (argc, argv) /* getopt_long_only is like getopt_long, but '-' as well as '--' can indicate a long option. */ int longind; - int optc = getopt_long_only (argc, argv, shortopts, longopts, &longind); + int optc; + + if (ldemul_parse_args (argc, argv)) + continue; + + optc = getopt_long_only (argc, argv, shortopts, longopts, &longind); if (optc == -1) break; - switch (optc) { default: @@ -248,6 +216,29 @@ parse_args (argc, argv) else einfo ("%P%F: unrecognized -a option `%s'\n", optarg); break; + case OPTION_ASSERT: + /* FIXME: We just ignore these, except for pure-text, but we + should handle them. */ + if (strcmp (optarg, "definitions") == 0) + ; + else if (strcmp (optarg, "nodefinitions") == 0) + ; + else if (strcmp (optarg, "nosymbolic") == 0) + ; + else if (strcmp (optarg, "pure-text") == 0) + { + /* FIXME: This is wrong. We do it this way as a hack to + support SunOS4, on which gcc -shared will pass + -assert pure-text to the linker. The SunOS linker + will automatically create a shared library if there + are any undefined symbols, but our linker does not + know how to do that (it seems to require an extra + pass over the relocs). */ + link_info.shared = true; + } + else + einfo ("%P%F: unrecognized -assert option `%s'\n", optarg); + break; case 'A': ldfile_add_arch (optarg); break; @@ -344,7 +335,6 @@ parse_args (argc, argv) something, or can we create a new option to do that (with a syntax similar to -defsym)? getopt can't handle two args to an option without kludges. */ - set_default_dirlist (optarg); break; case 'o': lang_add_output (optarg, 0); @@ -411,7 +401,7 @@ parse_args (argc, argv) case OPTION_SHARED: link_info.shared = true; break; - case 'h': /* Used on Solaris. */ + case 'h': /* Used on Solaris. */ case OPTION_SONAME: command_line.soname = optarg; break; @@ -490,7 +480,9 @@ parse_args (argc, argv) link_info.discard = discard_all; break; case 'Y': - set_default_dirlist (optarg); + if (strncmp (optarg, "P,", 2) == 0) + optarg += 2; + default_dirlist = optarg; break; case 'y': add_ysym (optarg); @@ -529,64 +521,15 @@ parse_args (argc, argv) ingroup = 0; break; - - - case OPTION_BASE_FILE: - link_info.base_file = (PTR) fopen (optarg,"w"); - if (link_info.base_file == NULL) - { - fprintf (stderr, "%s: Can't open base file %s\n", - program_name, optarg); - xexit (1); - } - break; - - /* PE options */ - case OPTION_HEAP: - set_pe_stack_heap (&pe_info.heap_reserve, &pe_info.heap_commit); - break; - case OPTION_STACK: - set_pe_stack_heap (&pe_info.stack_reserve, &pe_info.stack_commit); - break; - case OPTION_SUBSYSTEM: - set_pe_subsystem (); - break; - case OPTION_MAJOR_OS_VERSION: - set_pe_value (&pe_info.major_os_version); - break; - case OPTION_MINOR_OS_VERSION: - set_pe_value (&pe_info.minor_os_version); - break; - case OPTION_MAJOR_SUBSYSTEM_VERSION: - set_pe_value (&pe_info.major_subsystem_version); - break; - case OPTION_MINOR_SUBSYSTEM_VERSION: - set_pe_value (&pe_info.minor_subsystem_version); - break; - case OPTION_MAJOR_IMAGE_VERSION: - set_pe_value (&pe_info.major_image_version); - break; - case OPTION_MINOR_IMAGE_VERSION: - set_pe_value (&pe_info.minor_image_version); - break; - case OPTION_FILE_ALIGNMENT: - set_pe_value (&pe_info.file_alignment); - break; - case OPTION_SECTION_ALIGNMENT: - set_pe_value (&pe_info.section_alignment); - break; - case OPTION_DLL: - pe_info.dll.defined = 1; - pe_info.dll.value = 1; - break; - case OPTION_IMAGE_BASE: - set_pe_value (&pe_info.image_base); - break; } } if (ingroup) lang_leave_group (); + + if (default_dirlist != NULL) + set_default_dirlist (default_dirlist); + } /* Add the (colon-separated) elements of DIRLIST_PTR to the @@ -623,75 +566,3 @@ set_section_start (sect, valstr) lang_section_start (sect, exp_intop (val)); } -/* PE/WIN32; added routines to get the subsystem type, heap and/or stack - parameters which may be input from the command line */ - -static void -set_pe_subsystem () -{ - int i; - static struct - { - char *name ; - int value; - } - v[] = - { - {"native", BFD_PE_NATIVE}, - {"windows",BFD_PE_WINDOWS}, - {"console",BFD_PE_CONSOLE}, - {"os2",BFD_PE_OS2}, - {"posix", BFD_PE_POSIX}, - {0,0} - }; - - for (i = 0; v[i].name; i++) - { - if (!strcmp (optarg, v[i].name)) - { - link_info.pe_info = &pe_info; - pe_info.subsystem.value = v[i].value; - pe_info.subsystem.defined = 1; - return; - } - } - einfo ("%P%F: invalid subsystem type `%s'\n", optarg); -} - -static void -set_pe_value (ptr) - bfd_link_pe_info_dval *ptr; -{ - char *end; - ptr->value = strtoul (optarg, &end, 16); - if (end == optarg) - { - einfo ("%P%F: invalid hex number for PE parameter '%s'\n", optarg); - } - - optarg = end; - ptr->defined = 1; - link_info.pe_info = &pe_info; -} - -static void -set_pe_stack_heap (reserve, commit) - bfd_link_pe_info_dval *reserve; - bfd_link_pe_info_dval *commit; -{ - char *begin_commit; - char *end; - - set_pe_value (reserve); - if (*optarg == ',') - { - optarg++; - set_pe_value (commit); - } - else if (*optarg) - { - einfo ("%P%F: strange hex info for PE parameter '%s'\n", optarg); - } -} - - diff --git a/ld/scripttempl/aout.sc b/ld/scripttempl/aout.sc index 59e71fbdbec..f11deeacaee 100644 --- a/ld/scripttempl/aout.sc +++ b/ld/scripttempl/aout.sc @@ -7,7 +7,9 @@ ${STACKZERO+${RELOCATING+${STACKZERO}}} ${SHLIB_PATH+${RELOCATING+${SHLIB_PATH}}} SECTIONS { - .text ${RELOCATING+${TEXT_START_ADDR}}: + ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_START_ADDR};}} + ${CREATE_SHLIB+${RELOCATING+. = SIZEOF_HEADERS;}} + .text : { CREATE_OBJECT_SYMBOLS *(.text) @@ -19,22 +21,24 @@ SECTIONS *(.dynstr) *(.rules) *(.need) + ${RELOCATING+_etext = .;} + ${RELOCATING+__etext = .;} ${PAD_TEXT+${RELOCATING+. = ${DATA_ALIGNMENT};}} - ${RELOCATING+_etext = ${DATA_ALIGNMENT};} - ${RELOCATING+__etext = ${DATA_ALIGNMENT};} } - .data ${RELOCATING+${DATA_ALIGNMENT}} : + ${RELOCATING+. = ${DATA_ALIGNMENT};} + .data : { /* The first three sections are for SunOS dynamic linking. */ *(.dynamic) *(.got) *(.plt) *(.data) + *(.linux-dynamic) /* For Linux dynamic linking. */ ${CONSTRUCTING+CONSTRUCTORS} ${RELOCATING+_edata = .;} ${RELOCATING+__edata = .;} } - .bss ${RELOCATING+SIZEOF(.data) + ADDR(.data)} : + .bss : { ${RELOCATING+ __bss_start = .}; *(.bss) -- 2.30.2