diff options
Diffstat (limited to 'gcc/varasm.c')
-rw-r--r-- | gcc/varasm.c | 74 |
1 files changed, 40 insertions, 34 deletions
diff --git a/gcc/varasm.c b/gcc/varasm.c index 6c221459285..c92a5a08f42 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -1448,26 +1448,44 @@ default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED, #endif } -void -default_named_section_asm_out_destructor (rtx symbol, int priority) +/* Write the address of the entity given by SYMBOL to SEC. */ +void +assemble_addr_to_section (rtx symbol, section *sec) +{ + switch_to_section (sec); + assemble_align (POINTER_SIZE); + assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); +} + +/* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if + not) section for PRIORITY. */ +section * +get_cdtor_priority_section (int priority, bool constructor_p) { - const char *section = ".dtors"; char buf[16]; /* ??? This only works reliably with the GNU linker. */ + sprintf (buf, "%s.%.5u", + constructor_p ? ".ctors" : ".dtors", + /* Invert the numbering so the linker puts us in the proper + order; constructors are run from right to left, and the + linker sorts in increasing order. */ + MAX_INIT_PRIORITY - priority); + return get_section (buf, SECTION_WRITE, NULL); +} + +void +default_named_section_asm_out_destructor (rtx symbol, int priority) +{ + section *sec; + if (priority != DEFAULT_INIT_PRIORITY) - { - sprintf (buf, ".dtors.%.5u", - /* Invert the numbering so the linker puts us in the proper - order; constructors are run from right to left, and the - linker sorts in increasing order. */ - MAX_INIT_PRIORITY - priority); - section = buf; - } + sec = get_cdtor_priority_section (priority, + /*constructor_p=*/false); + else + sec = get_section (".dtors", SECTION_WRITE, NULL); - switch_to_section (get_section (section, SECTION_WRITE, NULL)); - assemble_align (POINTER_SIZE); - assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); + assemble_addr_to_section (symbol, sec); } #ifdef DTORS_SECTION_ASM_OP @@ -1475,9 +1493,7 @@ void default_dtor_section_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED) { - switch_to_section (dtors_section); - assemble_align (POINTER_SIZE); - assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); + assemble_addr_to_section (symbol, dtors_section); } #endif @@ -1501,23 +1517,15 @@ default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED, void default_named_section_asm_out_constructor (rtx symbol, int priority) { - const char *section = ".ctors"; - char buf[16]; + section *sec; - /* ??? This only works reliably with the GNU linker. */ if (priority != DEFAULT_INIT_PRIORITY) - { - sprintf (buf, ".ctors.%.5u", - /* Invert the numbering so the linker puts us in the proper - order; constructors are run from right to left, and the - linker sorts in increasing order. */ - MAX_INIT_PRIORITY - priority); - section = buf; - } + sec = get_cdtor_priority_section (priority, + /*constructor_p=*/true); + else + sec = get_section (".ctors", SECTION_WRITE, NULL); - switch_to_section (get_section (section, SECTION_WRITE, NULL)); - assemble_align (POINTER_SIZE); - assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); + assemble_addr_to_section (symbol, sec); } #ifdef CTORS_SECTION_ASM_OP @@ -1525,9 +1533,7 @@ void default_ctor_section_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED) { - switch_to_section (ctors_section); - assemble_align (POINTER_SIZE); - assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); + assemble_addr_to_section (symbol, ctors_section); } #endif |