Menu

#1188 configure replaces CFLAGS but honors LDFLAGS, leading to incompatible command lines

v3.6
closed-fixed
compyx
None
Buildsystem
2021-12-30
2020-01-30
No

When running ./configure , vice sometimes replaces CFLAGS from the environment with it's own CFLAGS. For example, in configure.ac:

old_CFLAGS="$CFLAGS"
CFLAGS="$VICE_CFLAGS"
dnl Do these checks before any Gtk3 flags are added
AC_MSG_CHECKING(for time_t in time.h)
AC_CACHE_VAL(bu_cv_decl_time_t_time_h,
[AC_TRY_COMPILE([#include <time.h>], [time_t i;],
bu_cv_decl_time_t_time_h=yes, bu_cv_decl_time_t_time_h=no)])
AC_MSG_RESULT($bu_cv_decl_time_t_time_h)
if test $bu_cv_decl_time_t_time_h = yes; then
  AC_DEFINE([HAVE_TIME_T_IN_TIME_H],,
        ¦   [Is the type time_t defined in <time.h>?])
fi

This can lead to a problem if there are flags in CFLAGS and LDFLAGS that interact. For example, if we run the following:

CFLAGS='-fPIE' LDFLAGS='-pie' ./configure

The configure will fail:

checking size of time_t... 0
configure: error: can not figure type of time_t

The actual failure from config.log is:

/usr/bin/ld: /tmp/ccHO6lM5.o: relocation R_X86_64_32 against `.rodata.str1.1' can not
be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status

We run into exactly this situation when trying to build Vice packages for Fedora, because CFLAGS includes...

-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1

...which sets -fPIE, and LDFLAGS includes...

-specs=/usr/lib/rpm/redhat/redhat-hardened-ld

...which sets -pie.

I've fixed this in my local package builds by simply comments out the line in configure that replaces CFLAGS. So I have:

old_CFLAGS="$CFLAGS"
#CFLAGS="$VICE_CFLAGS"

Discussion

  • compyx

    compyx - 2020-03-22

    I've updated the buildsystem to also use VICE_LDFLAGS in the way VICE_CFLAGS is currently used. Would surrounding configure tests with:

    old_LDFLAGS=$LDFLAGS
    LDFLAGS=$VICE_LDFLAGS
    # run some test
    LDFLAGS=$old_LDFLAGS
    

    work? (in addition to the CFLAGS replacements)

    Or do we require a different approach?

     
  • compyx

    compyx - 2020-10-01
    • status: open --> closed-fixed
    • assigned_to: compyx
    • Category: --> Buildsystem
     
  • compyx

    compyx - 2020-10-01

    No response for a long time, but I've checked current trunk with CFLAGS='-fPIE' LDFLAGS='-pie' ./configure and that runs configure fine, build fine and runs fine.

    So, I'm closing this as fixed. Please let me know if there are still issues.

     

Log in to post a comment.