[PATCH] bfd: Define pagesize variables only for mmap

Alan Modra amodra@gmail.com
Tue Apr 9 05:47:18 GMT 2024


On Mon, Apr 08, 2024 at 07:49:26PM -0700, H.J. Lu wrote:
> On Mon, Apr 8, 2024 at 3:55 PM Alan Modra <amodra@gmail.com> wrote:
> >
> > On Mon, Apr 08, 2024 at 07:26:37AM -0700, H.J. Lu wrote:
> > > On Sun, Apr 7, 2024 at 8:58 PM Simon Marchi <simon.marchi@polymtl.ca> wrote:
> > > > 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.
> >
> > You need to revert the change to lynx-core.c as well.
> 
> The v2 patch is at
> 
> https://sourceware.org/pipermail/binutils/2024-April/133466.html
> 
> > Somewhat related, why does binutils/elfedit.c depend on HAVE_MMAP?
> 
> It uses mmap to update the ELF program header directly.
> 
> > I run into failures with asan builds (ie. -fsanitize=address,undefined
> > in CFLAGS and CXXFLAGS passed to configure).
> > elfedit: unrecognized option '--enable-x86-feature'
> 
> I built binutils with GCC 13 using
> 
> CC="gcc -fsanitize=address,undefined" CXX="g++
> -fsanitize=address,undefined"
> /export/gnu/import/git/gitlab/x86-binutils/configure \
> --disable-werror --disable-gprofng \
> \
> --enable-plugins --disable-gdb --disable-gdbserver
> --disable-libbacktrace --disable-libdecnumber --disable-readline
> --disable-sim --enable-mark-plt --with-sysroot=/ --with-system-zlib \
> --prefix=/usr/local \
> --with-local-prefix=/usr/local
> 
> elfedit works:
> 
> [hjl@gnu-cfl-3 binutils]$ ./elfedit --enable-x86-feature ibt xx
> [hjl@gnu-cfl-3 binutils]$
> 
> > Apparently HAVE_MMAP configury fusses too much, see this comment:
> > gnulib/import/m4/mmap-anon.m4:  # Check for mmap(). Don't use AC_FUNC_MMAP, because it checks too much: it
> 
> It checks MAP_ANONYMOUS, not mmap:
> 
>   # Check for mmap(). Don't use AC_FUNC_MMAP, because it checks too much: it
>   # fails on HP-UX 11, because MAP_FIXED mappings do not work. But this is
>   # irrelevant for anonymous mappings.

Yes, it isn't that.  I fail to get HAVE_MMAP for the rather more
mundane reason that the config test fails with:
=================================================================
==231796==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7cdd3d0defdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x5750c7f6d72b in main /home/alan/build/gas-san/all/bfd/conftest.c:239

Direct leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7cdd3d0defdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x5750c7f6d2e1 in main /home/alan/build/gas-san/all/bfd/conftest.c:190

SUMMARY: AddressSanitizer: 8192 byte(s) leaked in 2 allocation(s).

This can be avoided by
export ASAN_OPTIONS=detect_leaks=0

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list