#17 Allow using of --as-needed

open
Roger Leigh
None
5
2014-08-12
2006-01-04
No

The attached patch adds a missing -lm linking to the
executables makefile allowing to use --as-needed
LDFLAG while building the package.

HTH,
Diego "Flameeyes" Pettenò
flameeyes@gentoo.org

Discussion

  • Robert Krawitz
    Robert Krawitz
    2006-01-05

    • assigned_to: nobody --> rleigh
     
  • Robert Krawitz
    Robert Krawitz
    2006-01-05

    Logged In: YES
    user_id=5436

    Roger, can you evaluate this? If this should be done, I'd
    like to do it for -rc2.

     
  • Roger Leigh
    Roger Leigh
    2006-01-09

    Logged In: YES
    user_id=116840

    Hi,

    The binaries are already linked to libm indirectly through
    libgutenprint. Why do they need direct linkage?

    Why are you using --as-needed? This option /removes/
    libraries from the link line after it is specified, so
    should be completely unaffected by adding -lm. In addition,
    for these binaries --as-needed should have no effect,
    because we are not linking any unneeded libraries (as far as
    I can tell).

    I'm not against the patch as such, I would just prefer to
    understand its purpose before adding it.

    Thanks,
    Roger

     
  • Logged In: YES
    user_id=60011

    Well seems like the linking of -lm in libgutenprint is
    discarded by --as-needed at least on my system, so the
    binaries losts its linkage.
    While on gutenprint it does not really do that much of a
    change, I'm trying to fix the cases where it does create
    failures using it generally for the system. While not
    using gnome, the number of failures I've seen is really
    low, so I've sent a few patches when it was the case.

     
  • Roger Leigh
    Roger Leigh
    2006-01-09

    Logged In: YES
    user_id=116840

    Does --as-needed fail for all the other binaries linked with
    libgutenprint?, or just these two?

    This looks like a bug in --as-needed in binutils, so this is
    what really needs fixing. The patch as it stands will break
    OS X (libm is part of System.dylib), so I would need to make
    some changes in configure to conditionally substitute it.

    If Robert thinks that's worth doing, I'll do that.

    Regards,
    Roger

     
  • Robert Krawitz
    Robert Krawitz
    2006-01-09

    Logged In: YES
    user_id=5436

    What is the purpose of --as-needed? How critical is the
    functionality?

     
  • Logged In: YES
    user_id=60011

    Okay I improved the patch now over rc2.
    The attached patch changes the check for libm in the
    configure to provide a MATH_LIB variable, and then add it
    to the linking of the binaries which fails.
    This works for OS X, too, as 10.3+ provides a link between
    libm.dylib to System.dylib, and for the previous versions
    the check will fail so the problem is avoided.

    For an explaination of --as-needed, I've wrote a simple
    guide on Gentoo Documentation:
    http://www.gentoo.org/proj/en/qa/asneeded.xml

     
  • Robert Krawitz
    Robert Krawitz
    2006-05-28

    Logged In: YES
    user_id=5436

    Roger, is this something we should do anything with? Should
    we keep it around and do it after 5.0, or close it?

     
  • Roger Leigh
    Roger Leigh
    2006-05-29

    Logged In: YES
    user_id=116840

    This patch looks like it's working around a binutils bug on
    Gentoo, when using a known buggy linker option.
    libgutenprint is linked with -lm, so all binaries linked
    with libgutenprint will link indirectly with libm.
    The --as-needed option is for some reason removing libm
    from DT_NEEDED, which is totally broken.

    I don't think we should be applying patches to work around
    breakage in a distribution, particularly when broken linker
    options are being used, so I think we should close the bug.

    The submitter has not provided any information about
    what /exactly/ is breaking. We have no specific details
    about what the --as-needed option changed, presumably the
    dynamic section in libgutenprint and/or the binaries. We
    need to understand what changed, (and why) before making
    any changes.

    We don't even know which version of binutils was used.

    Regards,
    Roger

     
  • Logged In: YES
    user_id=60011

    This is not a _binutils_ bug to work around, is a
    gimp-print bug. The link I provided (
    http://www.gentoo.org/proj/en/qa/asneeded.xml ) contains
    all the information about the flag and how it works. The
    binutils version is everything starting from 2.16.91.x, if
    it was a binutils bug, it wouldn't be there in 2.16.93
    that didn't die on any package up to now.

    What you are doing is simply linking libm on gutenprint
    _libraries_ that are *not* using functions from it, to
    avoid linking the two binaries using it, but --as-needed
    discards -lm linking _as it should_, *it's not a bug*, as
    you would know if you read that guide above (that once
    again has _all_ the information you need to know and even
    more).

     
  • Robert Krawitz
    Robert Krawitz
    2006-05-29

    Logged In: YES
    user_id=5436

    The guide itself contains the following:

    Warning: At the time of writing, there are many packages
    failing in funny ways because of --as-needed as they weren't
    designed to be used with it. While there shouldn't be (note
    the conditional) problems such as crashes, this flag is not
    considered safe for production use and not supported in any
    way by Gentoo.

    What is the impact of *not* doing this? What would be the
    impact if we were to hold off doing it for a while?

     
  • Logged In: YES
    user_id=60011

    The warning there is to avoid "ricers" (users that adds
    all the possible flags in the world and then file bugs
    without caring about whatever they did before, we're
    plenty of them :)). In general, there is no problem with
    the patch being used without --as-needed, actually it
    changes nothing but that's not the point.

    If you put this on hold, I suppose the worse that can
    happen is that we'll have to continue patching gutenprint
    and running automake on it for every user :) And so might
    other distributions, too. (AltLinux iirc is working on
    this, too).

     
  • Roger Leigh
    Roger Leigh
    2006-05-29

    Logged In: YES
    user_id=116840

    The page you provided a link to does not provide the
    information I need.

    I want to know, *specifically*, what is happening for
    gutenprint. I want a dump of the ELF private headers
    (objdump -p) for libgutenprint.so and also for both working
    and broken binaries both with and without this option, so
    that we can see *exactly* what is going on. That is, I
    want the information for:

    libgutenprint.so
    rastertogutenprint and/or genppd
    and then any other program e.g. canon or epson

    Your patch makes the CUPS binaries link with libm even when
    it is not required. The dependency is already fully
    described in DT_NEEDED:

    $ objdump -p /usr/lib/libgutenprint.so.2 | grep NEEDED
    NEEDED libm.so.6
    NEEDED libdl.so.2
    NEEDED libc.so.6

    If I link against this, I will always have an indirect libm
    dependency. If --as-needed breaks this, --as-needed is
    broken. The binary in question does not use any libm
    functions:

    $ nm -D /usr/lib/cups/filter/rastertogutenprint.5.0 |
    grep 'U '
    U close
    U cupsGetOption
    U cupsParseOptions
    U cupsRasterClose
    U cupsRasterOpen
    U cupsRasterReadHeader
    U cupsRasterReadPixels
    U fflush
    U fprintf
    U fwrite
    U getenv
    U gettimeofday
    U __libc_start_main
    U memset
    U open
    U perror
    U ppdClose
    U ppdFindOption
    U ppdOpenFile
    U signal
    U sleep
    U sprintf
    U stp_clear_string_parameter
    U stp_describe_parameter
    U stp_end_job
    U stp_free
    U stp_get_boolean_parameter
    U stp_get_boolean_parameter_active
    U stp_get_dimension_parameter
    U stp_get_dimension_parameter_active
    U stp_get_driver
    U stp_get_float_parameter
    U stp_get_float_parameter_active
    U stp_get_imageable_area
    U stp_get_int_parameter
    U stp_get_int_parameter_active
    U stp_get_left
    U stp_get_media_size
    U stp_get_page_height
    U stp_get_page_width
    U stp_get_papersize_by_name
    U stp_get_papersize_by_size
    U stp_get_parameter_list
    U stp_get_printer_by_driver
    U stp_get_printer_by_long_name
    U stp_get_release_version
    U stp_get_string_parameter
    U stp_get_string_parameter_active
    U stp_get_top
    U stp_get_version
    U stp_init
    U stp_malloc
    U stp_merge_printvars
    U stp_parameter_description_destroy
    U stp_parameter_list_count
    U stp_parameter_list_destroy
    U stp_parameter_list_param
    U stp_print
    U stp_printer_get_defaults
    U stp_set_boolean_parameter
    U stp_set_dimension_parameter
    U stp_set_errdata
    U stp_set_errfunc
    U stp_set_float_parameter
    U stp_set_height
    U stp_set_int_parameter
    U stp_set_left
    U stp_set_outdata
    U stp_set_outfunc
    U stp_set_page_height
    U stp_set_page_width
    U stp_set_printer_defaults
    U stp_set_string_parameter
    U stp_set_top
    U stp_set_width
    U stp_start_job
    U stp_string_list_count
    U stp_string_list_is_present
    U stp_string_list_param
    U stp_vars_create
    U stp_vars_create_copy
    U stp_vars_destroy
    U stp_verify
    U strcmp
    U strlen
    U strncmp
    U __strtod_internal
    U __strtol_internal
    U sysconf
    U times

    $ nm -D /usr/sbin/cups-genppd.5.0 | grep 'U '
    U bindtextdomain
    U closedir
    U dcgettext
    U __errno_location
    U exit
    U fprintf
    U fputc
    U free
    U fwrite
    U getopt
    U gzclose
    U gzopen
    U gzprintf
    U gzputs
    U __libc_start_main
    U malloc
    U memcpy
    U mkdir
    U opendir
    U printf
    U puts
    U qsort
    U readdir
    U realloc
    U setenv
    U setlocale
    U snprintf
    U stp_clear_string_parameter
    U stp_describe_parameter
    U stp_describe_resolution
    U stp_free
    U stp_get_maximum_imageable_area
    U stp_get_media_size
    U stp_get_papersize_by_name
    U stp_get_parameter_list
    U stp_get_printer_by_driver
    U stp_get_printer_by_index
    U stp_get_printer_by_long_name
    U stp_get_printer_index_by_driver
    U stp_get_size_limit
    U stp_init
    U stp_malloc
    U stp_parameter_description_destroy
    U stp_parameter_list_count
    U stp_parameter_list_destroy
    U stp_parameter_list_param
    U stp_printer_get_defaults
    U stp_printer_get_driver
    U stp_printer_get_family
    U stp_printer_get_long_name
    U stp_printer_get_manufacturer
    U stp_printer_model_count
    U stp_set_string_parameter
    U stp_string_list_count
    U stp_string_list_is_present
    U stp_string_list_param
    U stp_vars_create_copy
    U stp_vars_destroy
    U strcasecmp
    U strcmp
    U strcoll
    U strcpy
    U strerror
    U strlen
    U strncpy
    U textdomain
    U unsetenv
    U __xstat

    Please correct me if I am wrong, but I would like to
    understand the specifics.

    Thanks,
    Roger

     
  • Logged In: YES
    user_id=60011

    Okay, you probably didn't understand what --as-needded is
    designed for :) The dropped NEEDED line for libm.so is
    supposed to happen, because libgutenprint.so.2 does not
    import symbols from that. It's not broken, the code that
    relies on -lm being linked from that library is broken,
    rather. This is how linking is supposed to be in the first
    place.

    At least here on my system, both binaries requires the
    pow() function, that is in libm, and pow() is -probably
    not a coincidence- the function that's tested with
    AC_CHECK_LIB already.

    What you're doing right now is forcing an unneeded
    dependency over libm.so in libgutenprint.so.2, for the
    only sake of those two files (or maybe some other program
    that uses functions from libm but does not consider
    important explicitly link against libm (which is a broken
    behaviour).

     
  • Logged In: YES
    user_id=60011

    Okay, just noticed now a thing: rc2 forced the dependency
    although not using functions from libm; rc3 seems to use
    functions from there and libm is not discarded anymore, so
    it is somehow fixed, although the patch would be on the
    side of "play it safe".

    If you are still interested in the specifics, libdl.so is
    still discarded because it's not used.

     
  • Robert Krawitz
    Robert Krawitz
    2006-05-29

    Logged In: YES
    user_id=5436

    rc2 most certainly used the pow() function. The color code
    has used it since time immemorial.

    Forcing everything that links against libgutenprint to
    explicitly link against libm seems to me to be the wrong
    thing to do. It means that if we ever decide to import
    something else into gutenprint that anyone who links against
    it has to change their link line.

    I don't know if it's the same problem, but linking against
    libreadline is a real headache; it has dependencies on
    libncurses, libtermcap, or the like. We had to put some
    really ugly workaround code in our configure.ac to figure
    out what libreadline's dependencies are. If this patch
    forces other projects to do the same for us, I cannot see
    how it can be right.

    Please answer Roger's questions specifically.

     
  • Logged In: YES
    user_id=60011

    Well not in that library at least for what the linker
    could say. I must say it might be that for some reason
    that code wasn't enable for me, not sure.

    And no, --as-needed is not meant to create the same hell
    as older libreadline dependency hell, but to alleviate it.
    Basically it would force libreadline to _not_ force other
    software to figure out what it was built with, by linking
    the stuff it needs itself.

    Right now I don't have time for three rebuilds of
    gutenprint, if you want I can try to provide it tomorrow,
    but as I said, now it's no more a concern as rc3 fixed the
    thing already (although I have no clue how, tbh).

     
  • Roger Leigh
    Roger Leigh
    2006-05-29

    Logged In: YES
    user_id=116840

    > If you are still interested in the specifics, libdl.so
    > is still discarded because it's not used.

    That's not specific enough. I'd like actual details of
    what really happened and why, rather than vague
    descriptions.

    Note that libdl is most certainly used. If it's removed,
    it will break the module loader. This depends on the
    options given to configure, but if libdl was linked in, it
    is *required* for libgutenprint to function, because
    without the modules, the printer family drivers can't be
    used.

     
  • Roger Leigh
    Roger Leigh
    2006-05-29

    Logged In: YES
    user_id=116840

    I would still like the information from the builds. Note
    that you only need two builds: one with -Wl,--as-needed,
    and one without.

    This particular code hasn't been changed by us in the last
    year, and probably not in the last three since it is
    stable. I would suspect that updates to the Gentoo
    binutils are a more likely candidate for the breakage. In
    Debian, we did consider using --as-needed to reduce
    unneeded library dependencies, but it is still buggy and
    does cause breakage. The best long-term solution is to fix
    the tools and packages linking in unnecessary libraries,
    rather than papering over the problem with an ugly ld hack.

    Also note that --as-needed is not a universal panacea. It
    can only detect direct dependencies. It would miss things
    like _init/_fini or __attribute__(constructor/destructor)
    functions. We don't use those, but it could break C++
    static initialisers depending upon how the code is linked.
    There are also other cases where it will cause breakage.
    Sometimes libraries are required, even when there are no
    direct dependencies.

    In our case, the libm and libdl dependencies should never
    be removed, because libgutenprint uses them directly.

    $ nm -D /usr/lib/libgutenprint.so.2 | grep pow
    U pow

    $ nm -D /usr/lib/libgutenprint.so.2 | grep dl
    U dlclose
    U dlopen
    U dlsym

    Regards,
    Roger