varasm: Fix up __patchable_function_entries handling
The SECTION_LINK_ORDER changes don't seem to work properly.
If I compile:
static inline __attribute__((__gnu_inline__)) __attribute__((__unused__)) __attribute__((patchable_function_entry(0, 0))) int foo (int x)
{
return x + 1;
}
static inline __attribute__((__gnu_inline__)) __attribute__((__unused__)) __attribute__((patchable_function_entry(0, 0))) int bar (int x)
{
return x + 2;
}
int
baz (int x)
{
return foo (x) + 1;
}
int
qux (int x)
{
return bar (x) + 2;
}
(distilled from aarch64 Linux kernel) with
-O2 -fpatchable-function-entry=2 on aarch64 compiler configured against
latest binutils, I get:
...
.section __patchable_function_entries,"awo",@progbits,baz
...
.section __patchable_function_entries
...
in the assembly, but when it is assembled, one gets:
[ 4] __patchable_function_entries PROGBITS
0000000000000000 000060 000008 00 WAL 1 0 8
[ 5] .rela__patchable_function_entries RELA
0000000000000000 000280 000018 18 I 12 4 8
[ 6] __patchable_function_entries PROGBITS
0000000000000000 000068 000008 00 0 0 8
[ 7] .rela__patchable_function_entries RELA
0000000000000000 000298 000018 18 I 12 6 8
i.e. one writable allocated section with SHF_LINK_ORDER and another
non-allocated non-writable without link order. In the kernel case there is
always one entry in the WAL section and then dozens or more in the
non-allocated one.
The kernel then fails to link:
WARNING: modpost: vmlinux.o (__patchable_function_entries): unexpected non-allocatable section.
Did you forget to use "ax"/"aw" in a .S file?
Note that for example <linux/init.h> contains
section definitions for use in .S files.
ld: .init.data has both ordered [`__patchable_function_entries' in init/main.o] and unordered [`.init.data' in
+./drivers/firmware/efi/libstub/vsprintf.stub.o] sections
ld: final link failed: bad value
make: *** [Makefile:1175: vmlinux] Error 1
The following patch fixes it by always forcing full section flags for
SECTION_LINK_ORDER sections.
2020-12-16 Jakub Jelinek <jakub@redhat.com>
* varasm.c (default_elf_asm_named_section): Always force
section flags even for sections with SECTION_LINK_ORDER flag.