From 451133cefa839104aa127d230436fb609dbef37f Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Tue, 9 Jun 2015 23:06:29 -0400 Subject: gas: section name substitution sequence This patch adds the ability to automatically construct a section name based on the prior section. When gas is invoked with --sectname-subst, the occurrence of %S in a section name will be substituted by the name of the current section. For example: .macro exception_code .pushsection %S.exception [exception code here] .popsection .endm .text [code] exception_code [...] .section .init [init code] exception_code [...] The first and second exception_code invocations create the .text.exception and the .init.exception sections respectively. This is useful e.g. to discriminate between anciliary sections that are tied to .init code and can be discarded at run time when initialization is over vs anciliary sections tied to .text sections that need to stay resident. * as.c (show_usage): Document --sectname-subst. (parse_args): Add --sectname-subst. * as.h (flag_sectname_subst): New. * config/obj-elf.c (obj_elf_section_name): Add %S substitution. * doc/as.texinfo: Document it. --- gas/config/obj-elf.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'gas/config/obj-elf.c') diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index 4d7a8a7..78dc6d9 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -917,6 +917,27 @@ obj_elf_section_name (void) name = (char *) xmalloc (end - input_line_pointer + 1); memcpy (name, input_line_pointer, end - input_line_pointer); name[end - input_line_pointer] = '\0'; + + while (flag_sectname_subst) + { + char *subst = strchr (name, '%'); + if (subst && subst[1] == 'S') + { + int oldlen = strlen (name); + int substlen = strlen (now_seg->name); + int newlen = oldlen - 2 + substlen; + char *newname = (char *) xmalloc (newlen + 1); + int headlen = subst - name; + memcpy (newname, name, headlen); + strcpy (newname + headlen, now_seg->name); + strcat (newname + headlen, subst + 2); + xfree (name); + name = newname; + } + else + break; + } + #ifdef tc_canonicalize_section_name name = tc_canonicalize_section_name (name); #endif -- cgit v1.1