[PATCH v2] gas: Add --unique-pushsection

Jan Beulich jbeulich@suse.com
Sat May 17 07:37:08 GMT 2025


On 16.05.2025 23:15, H.J. Lu wrote:
> Linker kernel uses .pushsection directive extensively.  But when
> -ffunction-sections is used to build kernel, for
> 
> __attribute__((always_inline))
> static void inline
> test_section(void)
> {
>   asm goto("jmp 1f\n"
> 	   "\t.pushsection .alt_section, \"ax\"\n"
> 	   "1:\n"
> 	   "\tjmp %l[t_label]\n"
> 	   "\t.popsection\n"
> 	   : :
> 	   : : t_label);
> t_label:
>   return;
> }
> 
> void
> foo(void)
> {
>   test_section();
> }
> 
> void
> bar(void)
> {
>   test_section();
> }
> 
> we get
> 
> 	.text
> 	.section	.text.foo,"ax",@progbits
> 	.p2align 4
> 	.globl	foo
> 	.type	foo, @function
> foo:
> .LFB1:
> 	.cfi_startproc
> 	jmp 1f
> 	.pushsection .alt_section, "ax"
> 1:
> 	jmp .L2
> 	.popsection
> 
> .L2:
> 	ret
> .L3:
> 	.cfi_endproc
> .LFE1:
> 	.size	foo, .-foo
> 	.section	.text.bar,"ax",@progbits
> 	.p2align 4
> 	.globl	bar
> 	.type	bar, @function
> bar:
> .LFB2:
> 	.cfi_startproc
> 	jmp 1f
> 	.pushsection .alt_section, "ax"
> 1:
> 	jmp .L6
> 	.popsection
> 
> .L6:
> 	ret
> .L7:
> 	.cfi_endproc
> .LFE2:
> 	.size	bar, .-bar
> 
> Functions foo and bar are placed in the different sections.  But since
> ".pushsection .alt_section" always generates the same .alt_section
> section for foo and bar, --gc-sections doesn't remove foo when bar is
> referenced while foo isn't.  To help linker to remove the unreferenced
> functions with .pushsection directive:
> 
> Add --unique-pushsection option to ELF assembler to append the current
> section name to the new section name for .pushsection.
> 
> Another option is to replace ".pushsection .alt_section" with
> ".pushsection .alt_section%S" and compile with -Wa,--sectname-subst.

As before, this being enough, I see no reason why we would need new
logic to deal with a sub-case. Unless Nick or Alan view this
differently, this not NOT approved.

Jan


More information about the Binutils mailing list