X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=ld%2Fldlang.c;h=00d1e168d6b2bdf9d95f6a914ee8203be34c3aee;hb=357a1f38a539d43612122eb1c1842fd84859b165;hp=34bb2278cd5146b827d93e7e85130f668a9cad7b;hpb=e89432c7c9b2aa520dbde36817baffa763f4d654;p=binutils-gdb.git diff --git a/ld/ldlang.c b/ld/ldlang.c index 34bb2278cd5..00d1e168d6b 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -28,13 +28,13 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ld.h" #include "ldmain.h" #include "ldsym.h" -#include "ldgram.tab.h" -#include "ldmisc.h" +#include "ldgramtb.h" + #include "ldlang.h" #include "ldexp.h" #include "ldemul.h" #include "ldlex.h" - +#include "ldmisc.h" /* FORWARDS */ PROTO(static void, print_statements,(void)); PROTO(static void, print_statement,(lang_statement_union_type *, @@ -63,7 +63,7 @@ lang_input_statement_type *script_file = 0; boolean option_longmap = false; lang_statement_list_type file_chain = {0}; CONST char *entry_symbol = 0; -size_t largest_section = 0; +bfd_size_type largest_section = 0; boolean lang_has_input_file = false; lang_output_section_statement_type *create_object_symbols = 0; boolean had_output_filename = false; @@ -97,7 +97,32 @@ extern boolean write_map; #define outside_symbol_address(q) ((q)->value + outside_section_address(q->section)) +static void +DEFUN(print_size,(value), + size_t value) +{ + printf("%5x", (unsigned)value); +} +static void +DEFUN(print_alignment,(value), + unsigned int value) +{ + printf("2**%1u",value); +} +static void +DEFUN(print_fill,(value), + fill_type value) +{ + printf("%04x",(unsigned)value); +} + +static void +DEFUN(print_section,(name), + CONST char *CONST name) +{ + printf("%*s", -longest_section_name, name); +} /*---------------------------------------------------------------------- lang_for_each_statement walks the parse tree and calls the provided @@ -158,51 +183,6 @@ list->head = (lang_statement_union_type *)NULL; list->tail = &list->head; } -/*---------------------------------------------------------------------- - Functions to print the link map - */ - -static void -DEFUN(print_section,(name), - CONST char *CONST name) -{ - printf("%*s", -longest_section_name, name); -} -static void -DEFUN_VOID(print_space) -{ - printf(" "); -} -static void -DEFUN_VOID(print_nl) -{ - printf("\n"); -} -static void -DEFUN(print_address,(value), - bfd_vma value) -{ - printf("%8lx", value); -} -static void -DEFUN(print_size,(value), - size_t value) -{ - printf("%5x", (unsigned)value); -} -static void -DEFUN(print_alignment,(value), - unsigned int value) -{ - printf("2**%2u",value); -} - -static void -DEFUN(print_fill,(value), - fill_type value) -{ - printf("%04x",(unsigned)value); -} /*---------------------------------------------------------------------- @@ -214,7 +194,7 @@ static lang_statement_union_type* DEFUN(new_statement,(type, size, list), enum statement_enum type AND - size_t size AND + bfd_size_type size AND lang_statement_list_type *list) { lang_statement_union_type *new = (lang_statement_union_type *) @@ -383,7 +363,7 @@ DEFUN(lang_memory_region_lookup,(name), } { lang_memory_region_type *new = - (lang_memory_region_type *)ldmalloc(sizeof(lang_memory_region_type)); + (lang_memory_region_type *)ldmalloc((bfd_size_type)(sizeof(lang_memory_region_type))); new->name = buystring(name); new->next = (lang_memory_region_type *)NULL; @@ -469,21 +449,26 @@ DEFUN(lang_map,(outfile), { lang_memory_region_type *m; fprintf(outfile,"**MEMORY CONFIGURATION**\n\n"); - +#ifdef HOST_64_BIT fprintf(outfile,"name\t\torigin\t\tlength\t\tattributes\n"); +#else + fprintf(outfile,"name\t\torigin length\t\tattributes\n"); +#endif for (m = lang_memory_region_list; m != (lang_memory_region_type *)NULL; m = m->next) { fprintf(outfile,"%-16s", m->name); - - fprintf(outfile,"%08lx\t%08lx\t", m->origin, m->length); + print_address(m->origin); + print_space(); + print_address(m->length); + print_space(); print_flags(outfile, &m->flags); fprintf(outfile,"\n"); } fprintf(outfile,"\n\n**LINK EDITOR MEMORY MAP**\n\n"); - fprintf(outfile,"output\t\tinput\t\tvirtual\n"); - fprintf(outfile,"section\t\tsection\t\taddress\tsize\n\n"); + fprintf(outfile,"output input virtual\n"); + fprintf(outfile,"section section address tsize\n\n"); print_statements(); @@ -498,9 +483,14 @@ DEFUN(init_os,(s), { section_userdata_type *new = (section_userdata_type *) - ldmalloc(sizeof(section_userdata_type)); + ldmalloc((bfd_size_type)(sizeof(section_userdata_type))); s->bfd_section = bfd_make_section(output_bfd, s->name); + if (s->bfd_section == (asection *)NULL) { + info("%P%F output format %s cannot represent section called %s\n", + output_bfd->xvec->name, + s->name); + } s->bfd_section->output_section = s->bfd_section; s->bfd_section->flags = SEC_NO_FLAGS; /* We initialize an output sections output offset to minus its own */ @@ -775,7 +765,7 @@ DEFUN(ldlang_add_undef,(name), { ldlang_undef_chain_list_type *new = (ldlang_undef_chain_list_type - *)ldmalloc(sizeof(ldlang_undef_chain_list_type)); + *)ldmalloc((bfd_size_type)(sizeof(ldlang_undef_chain_list_type))); new->next = ldlang_undef_chain_list_head; ldlang_undef_chain_list_head = new; @@ -793,7 +783,7 @@ DEFUN_VOID(lang_place_undefineds) while (ptr != (ldlang_undef_chain_list_type*)NULL) { ldsym_type *sy = ldsym_get(ptr->name); asymbol *def; - asymbol **def_ptr = (asymbol **)ldmalloc(sizeof(asymbol **)); + asymbol **def_ptr = (asymbol **)ldmalloc((bfd_size_type)(sizeof(asymbol **))); def = (asymbol *)bfd_make_empty_symbol(script_file->the_bfd); *def_ptr= def; def->name = ptr->name; @@ -882,6 +872,10 @@ DEFUN(map_input_to_output_sections,(s, target, output_section_statement), lang_output_section_statement_lookup (s->address_statement.section_name); os->addr_tree = s->address_statement.address; + if (os->bfd_section == (asection *)NULL) { + info("%P%F can't set the address of undefined section %s\n", + s->address_statement.section_name); + } } break; case lang_input_statement_enum: @@ -1015,7 +1009,7 @@ DEFUN(print_input_section,(in), else { printf("%s", abfd->filename); } - printf("(%d bytes)", bfd_alloc_size(abfd)); + printf("(overhead %d bytes)", (int)bfd_alloc_size(abfd)); print_nl(); /* Find all the symbols in this file defined in this section */ @@ -1108,6 +1102,7 @@ DEFUN(print_wild_statement,(w,os), lang_wild_statement_type *w AND lang_output_section_statement_type *os) { + printf(" from "); if (w->filename != (char *)NULL) { printf("%s",w->filename); } @@ -1215,7 +1210,7 @@ DEFUN(insert_pad,(this_ptr, fill, power, output_section_statement, dot), { lang_statement_union_type *new = (lang_statement_union_type *) - ldmalloc(sizeof(lang_padding_statement_type)); + ldmalloc((bfd_size_type)(sizeof(lang_padding_statement_type))); /* Link into existing chain */ new->header.next = *this_ptr; *this_ptr = new; @@ -1413,7 +1408,7 @@ DEFUN(lang_size_sections,(s, output_section_statement, prev, fill, dot), { lang_statement_union_type *new = (lang_statement_union_type *) - ldmalloc(sizeof(lang_padding_statement_type)); + ldmalloc((bfd_size_type)(sizeof(lang_padding_statement_type))); /* Link into existing chain */ new->header.next = *prev; *prev = new; @@ -1616,44 +1611,55 @@ static void DEFUN_VOID(lang_check) { lang_statement_union_type *file; + unsigned long max_machine = bfd_get_machine(output_bfd); + unsigned long max_machine_seen = 0; + bfd * input_bfd; + unsigned long input_machine; + char *out_arch, *out_arch2; - for (file = file_chain.head; file != (lang_statement_union_type *)NULL; file=file->input_statement.next) { - /* Inspect the architecture and ensure we're linking like - with like - */ - - if (bfd_arch_compatible( file->input_statement.the_bfd, - output_bfd, - &ldfile_output_architecture, - &ldfile_output_machine)) { - bfd_set_arch_mach(output_bfd, - ldfile_output_architecture, ldfile_output_machine); - } - else { - enum bfd_architecture this_architecture = - bfd_get_architecture(file->input_statement.the_bfd); - unsigned long this_machine = + input_bfd = file->input_statement.the_bfd; + input_machine = bfd_get_machine(input_bfd); + + if ( input_machine > max_machine_seen ){ + max_machine_seen = input_machine; + } + + /* Inspect the architecture and ensure we're linking like with like */ + if ( (input_machine > max_machine) + || !bfd_arch_compatible( input_bfd, + output_bfd, + &ldfile_output_architecture, + NULL)) { + enum bfd_architecture this_architecture = + bfd_get_architecture(file->input_statement.the_bfd); + unsigned long this_machine = + bfd_get_machine(file->input_statement.the_bfd); - - info("%I: architecture %s", - file, - bfd_printable_arch_mach(this_architecture, this_machine)); - info(" incompatible with output %s\n", - bfd_printable_arch_mach(ldfile_output_architecture, - ldfile_output_machine)); + + /* Result of bfd_printable_arch_mach is not guaranteed to stick + around after next call, so we have to copy it. */ + out_arch = bfd_printable_arch_mach(ldfile_output_architecture, + ldfile_output_machine); + out_arch2 = ldmalloc (strlen (out_arch)+1); + strcpy (out_arch2, out_arch); + + info("%P: warning, %s architecture of input file `%B' incompatible with %s output\n", + bfd_printable_arch_mach(this_architecture, this_machine), + input_bfd, + out_arch2); + free (out_arch2); ldfile_output_architecture = this_architecture; ldfile_output_machine = this_machine; bfd_set_arch_mach(output_bfd, ldfile_output_architecture, ldfile_output_machine); - - } } + bfd_set_arch_mach(output_bfd,ldfile_output_architecture,max_machine_seen); } @@ -1959,7 +1965,7 @@ DEFUN(create_symbol,(name, flags, section), asection *section) { extern lang_input_statement_type *script_file; - asymbol **def_ptr = (asymbol **)ldmalloc(sizeof(asymbol **)); + asymbol **def_ptr = (asymbol **)ldmalloc((bfd_size_type)(sizeof(asymbol **))); /* Add this definition to script file */ asymbol *def = (asymbol *)bfd_make_empty_symbol(script_file->the_bfd); def->name = buystring(name);