Skip to content

Commit

Permalink
elf2flt: handle binutils >= 2.34
Browse files Browse the repository at this point in the history
The latest Binutils release (2.34) is not compatible with elf2flt due
to a change in bfd_section_* macros [1]. The issue has been reported
to the Binutils mailing list but Alan Modra recommend to bundle
libbfd library sources into each projects using it [2]. That's
because the API is not stable over the time without any backward
compatibility guaranties.

On the other hand, the elf2flt tools needs to support modified
version of binutils for specific arch/target [3].

Add two tests in the configure script to detect this API change
in order to support binutils < 2.34 and binutils >= 2.34.

Upstream status: [4]

[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=fd3619828e94a24a92cddec42cbc0ab33352eeb4
[2] https://sourceware.org/ml/binutils/2020-02/msg00044.html
[3] #14
[4] #15

Signed-off-by: Romain Naour <romain.naour@smile.fr>

Two changes made to original patch:
. $binutils_include_dir used for binutils version check
. configure script regenerated (run autoconf)

Signed-off-by: Greg Ungerer <gerg@kernel.org>
  • Loading branch information
RomainNaour authored and Greg Ungerer committed Apr 3, 2023
1 parent e827ca3 commit c70b9f2
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 37 deletions.
41 changes: 40 additions & 1 deletion configure
Expand Up @@ -676,6 +676,7 @@ infodir
docdir
oldincludedir
includedir
runstatedir
localstatedir
sharedstatedir
sysconfdir
Expand Down Expand Up @@ -759,6 +760,7 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE}'
Expand Down Expand Up @@ -1011,6 +1013,15 @@ do
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;

-runstatedir | --runstatedir | --runstatedi | --runstated \
| --runstate | --runstat | --runsta | --runst | --runs \
| --run | --ru | --r)
ac_prev=runstatedir ;;
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
| --run=* | --ru=* | --r=*)
runstatedir=$ac_optarg ;;

-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
Expand Down Expand Up @@ -1148,7 +1159,7 @@ fi
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
libdir localedir mandir
libdir localedir mandir runstatedir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
Expand Down Expand Up @@ -1301,6 +1312,7 @@ Fine tuning of the installation directories:
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
Expand Down Expand Up @@ -4379,6 +4391,33 @@ fi
done
if test "$binutils_include_dir" != "NONE"; then
CFLAGS="-I$binutils_include_dir -I$bfd_include_dir $CFLAGS"
fi
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <bfd.h>
int
main ()
{
const asection *sec; bfd_section_size(sec);
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
bfd_section_api_takes_bfd=no
else
bfd_section_api_takes_bfd=yes
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
if test "$bfd_section_api_takes_bfd" = "yes" ; then
$as_echo "#define HAVE_BFD_SECTION_API_TAKES_BFD 1" >>confdefs.h
fi
if test "$GCC" = yes ; then
CFLAGS="-Wall $CFLAGS"
if test "$werror" = 1 ; then
Expand Down
16 changes: 16 additions & 0 deletions configure.ac
Expand Up @@ -229,6 +229,22 @@ AC_CHECK_FUNCS([ \
strsignal \
])

dnl Various bfd section macros and functions like bfd_section_size() have been
dnl modified starting with binutils >= 2.34.
dnl Check if the prototypes take a bfd argument.
if test "$binutils_include_dir" != "NONE"; then
CFLAGS="-I$binutils_include_dir -I$bfd_include_dir $CFLAGS"
fi

AC_TRY_COMPILE([#include <bfd.h>],
[const asection *sec; bfd_section_size(sec);],
bfd_section_api_takes_bfd=no,
bfd_section_api_takes_bfd=yes)
if test "$bfd_section_api_takes_bfd" = "yes" ; then
AC_DEFINE(HAVE_BFD_SECTION_API_TAKES_BFD, 1,
[define to 1 for binutils < 2.34])
fi

if test "$GCC" = yes ; then
CFLAGS="-Wall $CFLAGS"
if test "$werror" = 1 ; then
Expand Down

0 comments on commit c70b9f2

Please sign in to comment.