[PATCH] gas: Add pushuniquesection and --unique-pushsection
H.J. Lu
hjl.tools@gmail.com
Fri May 16 06:15:27 GMT 2025
More information about the Binutils mailing list
Fri May 16 06:15:27 GMT 2025
- Previous message (by thread): [PATCH,V2 4/4] gas: sframe: handle .cfi_same_value
- Next message (by thread): [PATCH] gas: Add pushuniquesection and --unique-pushsection
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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:
1. Add --unique-pushsection option to ELF assembler to append the current
section name to the new section name for .pushsection.
2. Add ".pushuniquesection" directive to ELF assembler to append the
current section name to the new section name.
Tested with small test cases and kernel build, all working fine. Below
are the details:
OS: Ubuntu 24.04
GCC: 14.2.0 in Ubuntu default
Binutils: 2.44.50, built with this patch
Test cases:
1. compile test.c with assembler new parameter "--unique-pushsection"
2. modify test.c to use ".pushuniquesection" and compile
3. try (2) with "--unique-pushsection" parameter
4. build Linux kernel 6.12 with the new parameter for some specific files
All can see that unused functions were removed as expected and kernel
works correctly.
gas/
PR gas/32961
* NEWS: Mention --unique-pushsection and .pushuniquesection.
* as.c (flag_unique_pushsection): New.
(show_usage): Also show --unique-pushsection.
(parse_args): Support --unique-pushsection.
* as.h (flag_unique_pushsection): New.
* config/obj-elf.c (elf_pseudo_table): Add pushuniquesection.
(change_section): Change the push argument to int and append
the previous section name to the new section name for
.pushuniquesection or .pushsection with --unique-pushsection.
(obj_elf_change_section): Pass 0 to change_section.
* doc/as.texi: Document --unique-pushsection and
.pushuniquesection.
* testsuite/gas/elf/elf.exp: Run pushsection-1 and
pushsection-2.
* testsuite/gas/elf/pushsection-1.d: New file.
* testsuite/gas/elf/pushsection-1.s: Likewise.
* testsuite/gas/elf/pushsection-2.d: Likewise.
* testsuite/gas/elf/pushsection-2.s: Likewise.
ld/
PR gas/32961
* testsuite/ld-elf/pushsection-1.d: New file.
* testsuite/ld-elf/pushsection-1.s: Likewise.
* testsuite/ld-elf/pushsection-2.d: Likewise.
* testsuite/ld-elf/pushsection-2.s: Likewise.
* testsuite/ld-elf/pushsection-3.d: Likewise.
* testsuite/ld-elf/pushsection-3.s: Likewise.
* testsuite/ld-elf/pushsection-4.s: Likewise.
* testsuite/ld-elf/pushsection-4.d: Likewise.
--
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-gas-Add-pushuniquesection-and-unique-pushsection.patch
Type: text/x-patch
Size: 26769 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20250516/c0cec1ed/attachment-0001.bin>
- Previous message (by thread): [PATCH,V2 4/4] gas: sframe: handle .cfi_same_value
- Next message (by thread): [PATCH] gas: Add pushuniquesection and --unique-pushsection
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list