This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Documentation problem with TEXT_SECTION_ASM_OP

> -----Original Message-----
> From: [] On Behalf Of
> Joseph S. Myers
> Sent: 23 October 2012 15:28
> To: Paulo Matos
> Cc:
> Subject: Re: Documentation problem with TEXT_SECTION_ASM_OP
> conversions of other macros are welcome. 
> The list on that wiki page may be a bit out of date,
> but should still be a good starting point for this project.

I gave it a go with TEXT_SECTION_ASM_OP.

I started by changing crtstuff.c to use __LIBGCC_TEXT_SECTION_ASM_OP__ instead of TEXT_SECTION_ASM_OP.
I noticed crtstuff.c is not compiled with -fbuilding-libgcc so I added the flags to CRTSTUFF_T_CFLAGS in my makefile fragment.

Now to the changes in GCC itself:
 * Right where if(flag_building_libgcc) is, in c_cpp_builtins, the if becomes:
  /* For libgcc-internal use only.  */
  if (flag_building_libgcc)
      /* For libgcc enable-execute-stack.c.  */
      builtin_define_with_int_value ("__LIBGCC_TRAMPOLINE_SIZE__",
      /* For libgcc crtstuff.c. */
      builtin_define_with_value ("__LIBGCC_TEXT_SECTION_ASM_OP__",
				 TEXT_SECTION_ASM_OP, true);
      /* Is text_section always an unnamed section? */
      builtin_define_with_value ("__LIBGCC_TEXT_SECTION_ASM_OP__",
				 (const char *)text_section->, true);

The reason for the ifdef is because the docs allow the backend to define either TEXT_SECTION_ASM_OP or the text_section directly in TARGET_ASM_INIT_SECTIONS.
Therefore if we don't have TEXT_SECTION_ASM_OP we need to grab the text string from text_section. I assumed text_section was defined in TARGET_ASM_INIT_SECTIONS with an unnamed section (that's how I did it) but I am unsure if this is a general assumption.

Then remaining problem is that for preprocessing only no_backend from toplev.c is true and varasm initialization in that case doesn't run, so I changed do_compile to have:
      /* Set up the back-end if requested.  */
      if (!no_backend)
	backend_init ();
	init_varasm_once ();

This did the trick, but I am struggling with an interesting problem. 
Assume I want text_section asm op to be "\t.section .text, \"ax\"", so I would define 
#define TEXT_SECTION_ASM_OP "\t.section .text, \"ax\""

However, I decided to define it in TARGET_ASM_INIT_SECTIONS with:
text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
					"\t.section .text, \"ax\"");

But when this gets to libgcc, if I preprocess crtstuff.c __LIBGCC_TEXT_ASM_OP__ is defined to: 
#define __LIBGCC_TEXT_SECTION_ASM_OP__ "        .section .text, "axU""

If I debug cc1 to see what happens when this is defined I see that in builtin_define_with_value
Variable buf is defined to:
"__LIBGCC_TEXT_SECTION_ASM_OP__=\"\t.section .text, \"axU\"\""
Which is then passed to: cpp_define (parse_in, buf);

I can workaround this In my port by adjusting the definition of text_section but it is slightly annoying.
Do you have any hints as to why this happening and if there's a reasonable workaround?

Also, if you're interested in this code (with any changes you might suggest) as a patch, I am happy to prepare one.

Paulo Matos

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]