Bug 1804325

Summary: Linker garbage collection removes weak alias references.
Product: Red Hat Developer Toolset Reporter: Nick Clifton <nickc>
Component: binutilsAssignee: Nick Clifton <nickc>
Status: CLOSED CURRENTRELEASE QA Contact: Miloš Prchlík <mprchlik>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: DTS 9.1 RHEL 7CC: law, mcermak, mnewsome, mpolacek, ohudlick, sipoyare, tborcin
Target Milestone: alphaKeywords: Triaged
Target Release: 9.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: devtoolset-9-binutils-2.32-16.el7 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of:
: 1804328 (view as bug list) Environment:
Last Closed: 2020-06-05 13:25:22 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1804328, 1804687, 1804689, 1804696, 1804697    

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.