Re: [PATCH] gas: support for .pushsection and .popsection pseudo ops for coff
Jan Beulich <[email protected]> Fri, 24 Jul 2026 09:09:49 +0200
| Newsgroups | gmane.comp.gnu.binutils |
|---|---|
| Message-ID | <[email protected]> |
On 18.07.2026 18:22, Johannes Khoshnazar-Thoma wrote:
> Current Linux kernels make heavy use of the .pushsection and
> .popsection pseudo ops. Normally, the Linux kernel is built
> as an ELF object, where the assembler supports those pseudo
> ops. When compiling the Linux kernel as a Windows/ReactOS
> driver however, it must be compiled as a COFF object, since
> the Windows/ReactOS kernel does not know how to load ELF
> binaries.
>
> In order to be able to compile the Linux kernel as a COFF
> object (and further on as a PE32 native executable) the
> implementation of those pseudo ops has been copiied from
> the obj-elf.c support code to the obj-coff.c support code.
> It has been verified that the Linux kernel works without
> assembler errors when using an assembler with this patch.
First - don't you also need to support .previous then?
> --- a/gas/config/obj-coff.c
> +++ b/gas/config/obj-coff.c
> @@ -1536,6 +1536,32 @@ obj_coff_finalize_section_relocs (asection *sec, arelent **relocs,
> return true;
> }
>
> +struct section_stack
> +{
> + struct section_stack *next;
> + segT seg;
> + int subseg;
No matter that ELF uses int there, can this please be subsegT?
> +};
> +
> +static struct section_stack *section_stack;
> +
> +static void
> +obj_coff_popsection (int xxx ATTRIBUTE_UNUSED)
I understand the name is what ELF uses, but can this please be e.g. "ignore"
like obj_coff_section() had it before the change, and like many other directive
handler have it?
> +{
> + struct section_stack *top = section_stack;
> +
> + if (top == NULL)
> + {
> + as_warn (_(".popsection without corresponding .pushsection; ignored"));
> + return;
> + }
> +
> + section_stack = top->next;
> + subseg_set (top->seg, top->subseg);
> + free (top);
> +}
> +
> +
Nit: No (new) double blank lines please.
> @@ -1691,6 +1717,17 @@ obj_coff_section (int ignore ATTRIBUTE_UNUSED)
> }
> }
>
> + /* .pushsection implementation */
> + if (push)
I don't think the comment adds any value here.
> + {
> + struct section_stack *elt;
> + elt = XNEW (struct section_stack);
Can this please be the initializer of the variable?
> @@ -1903,6 +1940,8 @@ static const pseudo_typeS coff_pseudo_table[] =
> {"sect.s", obj_coff_section, 0},
> {"section", obj_coff_section, 0},
> {"section.s", obj_coff_section, 0},
> + {"pushsection", obj_coff_section, 1},
> + {"popsection", obj_coff_popsection, 0},
> /* FIXME: We ignore the MRI short attribute. */
> {"size", obj_coff_size, 0},
> {"tag", obj_coff_tag, 0},
This table attempts to have its entries sorted by name. Please insert accordingly.
Also you didn't copy what elf_end() has; please do.
Jan