[PATCH] bfd: Define pagesize variables only for mmap

H.J. Lu hjl.tools@gmail.com
Mon Apr 8 14:26:37 GMT 2024


On Sun, Apr 7, 2024 at 8:58 PM Simon Marchi <simon.marchi@polymtl.ca> wrote:
>
>
>
> On 2024-03-17 08:19, H.J. Lu wrote:
> > There are many linker input files in LLVM debug build with huge string
> > sections.  All these string sections can be treated as read-only.  But
> > linker copies all of them into memory which consumes huge amount of
> > memory and slows down linker significantly.
> >
> > Add _bfd_mmap_readonly_persistent and _bfd_mmap_readonly_temporary to
> > mmap in reado-only sections with size >= 4 * page size.
> >
> > NB: All string sections in valid ELF inputs must be null terminated.
> > There is no need to terminate it again and string sections are mmapped
> > as read-only.
> >
> >       * bfd.c (bfd_mmapped_entry): New.
> >       (bfd_mmapped): Likewise.
> >       (bfd): Add mmapped.
> >       * bfdwin.c (bfd_get_file_window): Use _bfd_pagesize.
> >       * cache.c (cache_bmmap): Remove pagesize_m1 and use pagesize_m1
> >       instead.
> >       * elf.c (bfd_elf_get_str_section): Call
> >       _bfd_mmap_readonly_persistent instead of _bfd_alloc_and_read.
> >       Don't terminate the string section again.
> >       (get_hash_table_data): Call _bfd_mmap_readonly_temporary and
> >       _bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
> >       and free.
> >       (_bfd_elf_get_dynamic_symbols): Call _bfd_mmap_readonly_persistent
> >       instead of _bfd_alloc_and_read.  Don't terminate the string
> >       section again.  Call _bfd_mmap_readonly_temporary and
> >       _bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
> >       and free.
> >       (_bfd_elf_slurp_version_tables): Call _bfd_mmap_readonly_temporary
> >       and _bfd_munmap_readonly_temporary instead of _bfd_malloc_and_read
> >       and free.
> >       * elflink.c (bfd_elf_link_record_dynamic_symbol): Use bfd_malloc
> >       to get the unversioned symbol.
> >       * libbfd-in.h (_bfd_pagesize): New.
> >       (_bfd_pagesize_m1): Likewise.
> >       (_bfd_minimum_mmap_size): Likewise.
> >       (_bfd_mmap_readonly_persistent): Likewise.
> >       (_bfd_mmap_readonly_temporary): Likewise.
> >       (_bfd_munmap_readonly_temporary): Likewise.
> >       * libbfd.c
> >       (bfd_allocate_mmapped_page): New.
> >       (_bfd_mmap_readonly_temporary): Likewise.
> >       (_bfd_munmap_readonly_temporary): Likewise.
> >       (_bfd_mmap_readonly_persistent): Likewise.
> >       (_bfd_pagesize): Likewise.
> >       (_bfd_pagesize_m1): Likewise.
> >       (_bfd_minimum_mmap_size): Likewise.
> >       (bfd_init_pagesize): Likewise.
> >       * lynx-core.c (lynx_core_file_p): Use _bfd_pagesize.
> >       * opncls.c (_bfd_delete_bfd): Munmap tracked mmapped memories.
> >       * sysdep.h (MAP_ANONYMOUS): New. Define if undefined.
> >       * bfd-in2.h: Regenerated.
> >       * libbfd.h: Likewise.
>
> Hi,
>
> Since this commit, when building for --host=x86_64-w64-mingw32, I get:
>
>
> make[4]: Entering directory '/home/simark/build/binutils-gdb-x86_64-w64-mingw32/bfd'
>   CC       libbfd.lo
> /home/simark/src/binutils-gdb/bfd/libbfd.c: In function ‘bfd_init_pagesize’:
> /home/simark/src/binutils-gdb/bfd/libbfd.c:1583:19: error: implicit declaration of function ‘getpagesize’ [-Werror=implicit-function-declaration]
>  1583 |   _bfd_pagesize = getpagesize ();
>       |                   ^~~~~~~~~~~
>
> Simon

Please try this patch.

-- 
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-bfd-Define-pagesize-variables-only-for-mmap.patch
Type: application/x-patch
Size: 2337 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20240408/3d53b5c7/attachment.bin>


More information about the Binutils mailing list