public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: "H.J. Lu" <hjl.tools@gmail.com>, binutils@sourceware.org
Cc: goldstein.w.n@gmail.com, sam@gentoo.org, amodra@gmail.com
Subject: Re: [PATCH v12 1/6] elf: Use mmap to map in read-only sections
Date: Sun, 7 Apr 2024 23:57:44 -0400	[thread overview]
Message-ID: <6665080c-42e3-4fd7-a843-460de7cef778@polymtl.ca> (raw)
In-Reply-To: <20240317121912.799372-2-hjl.tools@gmail.com>



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

  reply	other threads:[~2024-04-08  3:58 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-17 12:19 [PATCH v12 0/6] elf: Use mmap to map in section contents H.J. Lu
2024-03-17 12:19 ` [PATCH v12 1/6] elf: Use mmap to map in read-only sections H.J. Lu
2024-04-08  3:57   ` Simon Marchi [this message]
2024-04-08 14:26     ` [PATCH] bfd: Define pagesize variables only for mmap H.J. Lu
2024-04-08 22:55       ` Alan Modra
2024-04-09  2:49         ` H.J. Lu
2024-04-09  5:47           ` Alan Modra
2024-04-09 14:25             ` H.J. Lu
2024-03-17 12:19 ` [PATCH v12 2/6] elf: Add _bfd_elf_m[un]map_section_contents H.J. Lu
2024-03-17 12:19 ` [PATCH v12 3/6] elf: Use mmap to map in symbol and relocation tables H.J. Lu
2024-03-17 12:19 ` [PATCH v12 4/6] elf: Don't cache symbol nor relocation tables with mmap H.J. Lu
2024-03-17 12:19 ` [PATCH v12 5/6] elf: Always keep symbol table and relocation info for eh_frame H.J. Lu
2024-03-17 12:19 ` [PATCH v12 6/6] elf: Add _bfd_elf_link_m[un]map_section_contents H.J. Lu
2024-03-28 13:29 ` PING: [PATCH v12 0/6] elf: Use mmap to map in section contents H.J. Lu
2024-04-03 16:03   ` Nick Clifton
2024-04-04 13:12 ` Luis Machado
2024-04-04 13:53   ` H.J. Lu
2024-04-04 20:27   ` Joseph Myers
2024-04-04 22:22     ` Alan Modra
2024-04-04 22:43       ` Joseph Myers
2024-04-04 22:46         ` H.J. Lu
2024-04-04 23:20           ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6665080c-42e3-4fd7-a843-460de7cef778@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=goldstein.w.n@gmail.com \
    --cc=hjl.tools@gmail.com \
    --cc=sam@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).