https://sourceware.org/bugzilla/show_bug.cgi?id=25458
Bug ID: 25458 Summary: --gc-sections removes _environ symbol since version 2.21 Product: binutils Version: 2.35 (HEAD) Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: andrew at ishiboo dot com Target Milestone: --- 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@GLIBC_2.2.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. Code x-reference: https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/arena.c;h=4d0deefe19156a46d7d51a8da5d7b1f8e4e2afdd;hb=6164128f1ca84eea240b66f977054e16b94b3c86#l541 The `gold` linker does not discard the `_environ` symbol when `--gc-sections` is used: $ gcc -fuse-ld=gold -Wl,--gc-sections -o environ environ.c && \ readelf -s environ | grep " _environ" 5: 0000000000402040 8 OBJECT GLOBAL DEFAULT 24 _environ@GLIBC_2.2.5 (2) 31: 0000000000402040 8 OBJECT GLOBAL DEFAULT 24 _environ This was checked against older versions of `ld` and version 2.20 works and retains the `_environ` symbol. Searching for changes that occurred in the release of 2.21, it appears this commit for bug 20828 changed the behavior: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=81ff47b3a54633819fac4d973e34f1ff0c65606e https://www.sourceware.org/ml/binutils/2017-01/msg00263.html -- You are receiving this mail because: You are on the CC list for the bug.