From 8f6b012b22ff372e782b6e49b4451411524e28f2 Mon Sep 17 00:00:00 2001 From: midipix Date: Wed, 27 Feb 2019 15:45:06 -0500 Subject: midipix targets: .gotrefs: allow linker to sort entries by target section. --- gcc/config/i386/midipix.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/gcc/config/i386/midipix.c b/gcc/config/i386/midipix.c index 01f40c5a5..896e3bef2 100644 --- a/gcc/config/i386/midipix.c +++ b/gcc/config/i386/midipix.c @@ -580,6 +580,8 @@ bool midipix_asm_assemble_integer(rtx x, unsigned int size, int aligned_p) const char * name; const char * ptrsize; const char * secname; + const char * sortname; + char namebuf[2048]; /* filter out c++ constructors */ if (flag_assume_static_linking) @@ -637,12 +639,6 @@ bool midipix_asm_assemble_integer(rtx x, unsigned int size, int aligned_p) fprintf (asm_out_file,HOST_WIDE_INT_PRINT_DEC,INTVAL(xoff)); } - /* .gotrefs section */ - fputs("\n\n",asm_out_file); - fputs(GAS_SECTION,asm_out_file); - fputs(GOTREFS_SECTION_NAME,asm_out_file); - fputs("\n",asm_out_file); - /* back reference: section name */ if (!in_section) gcc_unreachable(); @@ -674,6 +670,24 @@ bool midipix_asm_assemble_integer(rtx x, unsigned int size, int aligned_p) gcc_unreachable(); } + if (!(sortname = strchr(secname,'$'))) { + sortname = secname; + } else if (sortname-secname >= sizeof(namebuf)) { + gcc_unreachable(); + } else { + memcpy(namebuf,secname,sortname-secname); + namebuf[sortname-secname] = 0; + sortname = namebuf; + } + + /* .gotrefs section */ + fputs("\n\n",asm_out_file); + fputs(GAS_SECTION,asm_out_file); + fputs(GOTREFS_SECTION_NAME,asm_out_file); + fputs("$",asm_out_file); + fputs(sortname,asm_out_file); + fputs("\n",asm_out_file); + /* back reference: section rva */ fputs("\t.rva",asm_out_file); fprintf(asm_out_file,"\t%s\n",secname); -- cgit v1.2.3