Bug 1804325 - Linker garbage collection removes weak alias references.
Summary: Linker garbage collection removes weak alias references.
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Developer Toolset
Classification: Red Hat
Component: binutils
Version: DTS 9.1 RHEL 7
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: alpha
: 9.0
Assignee: Nick Clifton
QA Contact: Miloš Prchlík
URL:
Whiteboard:
Depends On:
Blocks: 1804328 1804687 1804689 1804696 1804697
TreeView+ depends on / blocked
 
Reported: 2020-02-18 17:10 UTC by Nick Clifton
Modified: 2020-10-05 08:30 UTC (History)
7 users (show)

Fixed In Version: devtoolset-9-binutils-2.32-16.el7
Doc Type: No Doc Update
Doc Text:
Clone Of:
: 1804328 (view as bug list)
Environment:
Last Closed: 2020-06-05 13:25:22 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Sourceware 25458 0 P2 RESOLVED --gc-sections removes _environ symbol since version 2.21 2020-06-03 12:06:37 UTC

Description Nick Clifton 2020-02-18 17:10:03 UTC
Description of problem:

The following issue is observed in all `ld` versions >= 2.21. Version 2.20 does not exhibit this behavior.

A simple C file:

    #include <stdio.h>
    extern char **environ;
    int main(int argc, char **argv) {
        printf("%p\n", environ);
        return 0;
    }

When compiled, will reference `_environ`:

    $ gcc -o environ environ.c && \
      readelf -s environ | grep " _environ"
         4: 0000000000601040     8 OBJECT  WEAK   DEFAULT   24 _environ.5 (2)
    $

When compiled passing the linker `--gc-sections`, the `_environ` alias is dropped, but the `__environ` and `environ` ones remain:

    $ gcc -Wl,--gc-sections -o environ environ.c && \
      readelf -s environ | grep " _environ"
    $

This breaks glibc functionality that looks at `_environ` internally, because it then points to a different address when the shared object is loaded. This manifested in glibc not respecting memory sub-system environment variables.

Comment 2 Nick Clifton 2020-02-19 08:34:25 UTC
Fixed in devtoolset-9-binutils-2.32-16.el7

Comment 6 Miloš Prchlík 2020-06-05 13:25:22 UTC
This issue is no longer reproducible with DTS 9.1 and devtoolset-9-binutils-2.32-16.el7.


Note You need to log in before you can comment on or make changes to this bug.