From 3020f72618e4f1d7338cd42b8bc7b2813e961b5a Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Netto Date: Tue, 27 Dec 2022 18:11:43 -0300 Subject: libio: Remove the usage of __libc_IO_vtables Instead of using a special ELF section along with a linker script directive to put the IO vtables within the RELRO section, the libio vtables are all moved to an array marked as data.relro (so linker will place in the RELRO segment without the need of extra directives). To avoid static linking namespace issues and including all vtable referenced objects, all required function pointers are set to weak alias. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Carlos O'Donell --- include/libc-symbols.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/libc-symbols.h b/include/libc-symbols.h index 155781d448..37c91bb3a4 100644 --- a/include/libc-symbols.h +++ b/include/libc-symbols.h @@ -243,20 +243,26 @@ for linking") This is only necessary when defining something in assembly, or playing funny alias games where the size should be other than what the compiler thinks it is. */ -#ifdef __ASSEMBLER__ -# define declare_object_symbol_alias(symbol, original, size) \ +#define declare_object_symbol_alias(symbol, original, size) \ declare_object_symbol_alias_1 (symbol, original, size) +#ifdef __ASSEMBLER__ # define declare_object_symbol_alias_1(symbol, original, s_size) \ strong_alias (original, symbol) ASM_LINE_SEP \ .type C_SYMBOL_NAME (symbol), %object ASM_LINE_SEP \ .size C_SYMBOL_NAME (symbol), s_size ASM_LINE_SEP #else /* Not __ASSEMBLER__. */ # ifdef HAVE_ASM_SET_DIRECTIVE -# define declare_symbol_alias_1_alias(symbol, original) \ - ".set " __SYMBOL_PREFIX #symbol ", " __SYMBOL_PREFIX #original +# define declare_object_symbol_alias_1(symbol, original, size) \ + asm (".global " __SYMBOL_PREFIX # symbol "\n" \ + ".type " __SYMBOL_PREFIX # symbol ", %object\n" \ + ".set " __SYMBOL_PREFIX #symbol ", " __SYMBOL_PREFIX original "\n" \ + ".size " __SYMBOL_PREFIX #symbol ", " #size "\n"); # else -# define declare_symbol_alias_1_alias(symbol, original) \ - __SYMBOL_PREFIX #symbol " = " __SYMBOL_PREFIX #original +# define declare_object_symbol_alias_1(symbol, original, size) \ + asm (".global " __SYMBOL_PREFIX # symbol "\n" \ + ".type " __SYMBOL_PREFIX # symbol ", %object\n" \ + __SYMBOL_PREFIX #symbol " = " __SYMBOL_PREFIX original "\n" \ + ".size " __SYMBOL_PREFIX #symbol ", " #size "\n"); # endif /* HAVE_ASM_SET_DIRECTIVE */ #endif /* __ASSEMBLER__ */ -- cgit 1.4.1