[PATCH v2 2/4] libio: Remove the usage of __libc_IO_vtables

Florian Weimer fweimer@redhat.com
Fri Dec 23 16:17:52 GMT 2022


* Adhemerval Zanella:

> Instead of using a special ELF section along with a linker script
> directive to put the IO vtables within the section, the libio vtables
> are moved to an array marked as data.relro (so linker will place in
> the RELRO segment without the need of extra linker directives).
>
> To avoid static linking namespace issues and to pulling all vtables
> referenced objects, all function pointers are set to weak alias.

I checked if it is easy to remove more vtables, but it's not.  I've got
a vscanf conversion, but we're still stuck with the strfile vtable due
to other uses.
> diff --git a/libio/vtables.c b/libio/vtables.c
> index e3809c28ce..ac767e1b67 100644
> --- a/libio/vtables.c
> +++ b/libio/vtables.c
> @@ -21,6 +21,514 @@
>  #include <stdio.h>
>  #include <ldsodefs.h>
>  #include <pointer_guard.h>
> +#include <libio-macros.h>
> +
> +#ifndef SHARED
> +# pragma weak _IO_default_close
> +# pragma weak _IO_default_doallocate
> +# pragma weak _IO_default_imbue
> +# pragma weak _IO_default_pbackfail
> +# pragma weak _IO_default_read
> +# pragma weak _IO_default_seek
> +# pragma weak _IO_default_seekpos
> +# pragma weak _IO_default_setbuf
> +# pragma weak _IO_default_showmanyc
> +# pragma weak _IO_default_stat
> +# pragma weak _IO_default_sync
> +# pragma weak _IO_default_uflow
> +# pragma weak _IO_default_write
> +# pragma weak _IO_default_xsgetn
> +# pragma weak _IO_default_xsputn
> +
> +# pragma weak _IO_wdefault_pbackfail
> +# pragma weak _IO_wdefault_uflow
> +# pragma weak _IO_wdefault_doallocate
> +# pragma weak _IO_wdefault_xsgetn
> +# pragma weak _IO_wdefault_xsputn
> +
> +# pragma weak _IO_str_finish
> +# pragma weak _IO_str_overflow
> +# pragma weak _IO_str_pbackfail
> +# pragma weak _IO_str_seekoff
> +# pragma weak _IO_str_underflow

These should not be weak because they are currently pulled into every
link.

> +# pragma weak _IO_wstr_finish
> +# pragma weak _IO_wstr_overflow
> +# pragma weak _IO_wstr_pbackfail
> +# pragma weak _IO_wstr_seekoff
> +# pragma weak _IO_wstr_underflow

These can be weak, I think.

> +# pragma weak _IO_file_close
> +# pragma weak _IO_file_close_mmap
> +# pragma weak _IO_file_doallocate
> +# pragma weak _IO_file_finish
> +# pragma weak _IO_file_jumps_alia
> +# pragma weak _IO_file_overflow
> +# pragma weak _IO_file_read
> +# pragma weak _IO_file_seek
> +# pragma weak _IO_file_seekoff_maybe_mmap
> +# pragma weak _IO_file_seekoff_mmap
> +# pragma weak _IO_file_setbuf
> +# pragma weak _IO_file_setbuf_mmap
> +# pragma weak _IO_file_setbuf_mmap
> +# pragma weak _IO_file_stat
> +# pragma weak _IO_file_sync
> +# pragma weak _IO_file_sync_mmap
> +# pragma weak _IO_file_underflow
> +# pragma weak _IO_file_underflow_maybe_mmap
> +# pragma weak _IO_file_underflow_mmap
> +# pragma weak _IO_file_xsgetn
> +# pragma weak _IO_file_xsgetn_maybe_mmap
> +# pragma weak _IO_file_xsgetn_mmap
> +# pragma weak _IO_file_xsputn
> +
> +# pragma weak _IO_wfile_overflow
> +# pragma weak _IO_wfile_sync
> +# pragma weak _IO_wfile_underflow
> +# pragma weak _IO_wfile_underflow_maybe_mmap
> +# pragma weak _IO_wfile_underflow_mmap
> +# pragma weak _IO_wfile_doallocate
> +# pragma weak _IO_wfile_jumps_alia
> +# pragma weak _IO_wfile_seekoff
> +# pragma weak _IO_wfile_xsputn
> +
> +# pragma weak _IO_new_file_finish
> +# pragma weak _IO_new_file_overflow
> +# pragma weak _IO_new_file_seekoff
> +# pragma weak _IO_new_file_setbuf
> +# pragma weak _IO_new_file_sync
> +# pragma weak _IO_new_file_underflow
> +# pragma weak _IO_new_file_write
> +# pragma weak _IO_new_file_xsputn
> +# pragma weak _IO_new_proc_close

These above should not be weak because they are pulled in always.

> +# pragma weak _IO_cookie_close
> +# pragma weak _IO_cookie_read
> +# pragma weak _IO_cookie_seek
> +# pragma weak _IO_cookie_seekoff
> +# pragma weak _IO_cookie_write
> +
> +# pragma weak _IO_mem_finish
> +# pragma weak _IO_mem_sync
> +
> +# pragma weak _IO_wmem_finish
> +# pragma weak _IO_wmem_sync
> +
> +# pragma weak __printf_buffer_as_file_overflow
> +# pragma weak __printf_buffer_as_file_xsputn
> +
> +# pragma weak __wprintf_buffer_as_file_overflow
> +# pragma weak __wprintf_buffer_as_file_xsputn

The above ones could be weak, I think.

> +# pragma weak _IO_old_cookie_seek
> +# pragma weak _IO_old_file_finish
> +# pragma weak _IO_old_file_overflow
> +# pragma weak _IO_old_file_seekoff
> +# pragma weak _IO_old_file_setbuf
> +# pragma weak _IO_old_file_sync
> +# pragma weak _IO_old_file_underflow
> +# pragma weak _IO_old_file_write
> +# pragma weak _IO_old_file_xsputn
> +# pragma weak _IO_old_proc_close
> +#endif

The *_old_* functions should not be weak because they cannot show up in
a static link.  SHLIB_COMPAT should filter them out, too.

Thanks,
Florian



More information about the Libc-alpha mailing list