Bug 80717 - LTO wrappers segfault if run with absolute path
Summary: LTO wrappers segfault if run with absolute path
Status: RESOLVED DUPLICATE of bug 81829
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: 7.1.1
: P3 normal
Target Milestone: 7.3
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-12 00:59 UTC by Hao Zhang
Modified: 2021-12-24 08:48 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-05-12 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hao Zhang 2017-05-12 00:59:45 UTC
When I run any of the LTO wrappers (gcc-ar, gcc-nm, gcc-ranlib) with absolute path (e.g. /usr/bin/gcc-ar), the program segfaults immediately. I tried to run some debugging, and I found the culprit is in line 197-204 of gcc-ar.c.

Basically gcc-ar was trying to find ar, and "/usr/bin/" was removed from the list of path to search for ar in line 203 of gcc-ar.c. As a result ar cannot be found and the program segfaults.

I'm using Arch Linux and my gcc version info is as follows:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/hao/code/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,lto --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release
Thread model: posix
gcc version 7.1.1 20170508 (GCC)
Comment 1 Richard Biener 2017-05-12 06:57:37 UTC
It seems to work for me:

> /usr/bin/gcc-ar-7 t t.a
t.o

any specific command-line to try?  I suppose for me it finds ar with the first

  /* Find the wrapped binutils program.  */
  exe_name = find_a_file (&target_path, PERSONALITY, X_OK);
  if (!exe_name)
    {
Comment 2 Hao Zhang 2017-05-12 07:37:46 UTC
Thank you for your reply. For me basically any arguments with /usr/bin/gcc-ar fails with segfault, even running /usr/bin/gcc-ar with no additional arguments at all. 

When I run gcc-ar with gdb (here I don't even need to have the absolute path, "gdb gcc-ar" fails with segfault), before line 203 of gcc-ar.c, the variable path.plist consists of the following entries:

{0x6070a0 "/usr/local/sbin/",  0x607010 "/usr/local/bin/", 0x6073c0 "/usr/bin/", 0x607400 "/usr/lib/jvm/default/bin/", 0x607450 "/usr/bin/site_perl/", 0x607490 "/usr/bin/vendor_perl/", 0x6074d0 "/usr/bin/core_perl/"}

After line 203, /usr/bin/ is removed from the list of paths:

{0x6070a0 "/usr/local/sbin/",  0x607010 "/usr/local/bin/", 0x0 , 0x607400 "/usr/lib/jvm/default/bin/", 0x607450 "/usr/bin/site_perl/", 0x607490 "/usr/bin/vendor_perl/", 0x6074d0 "/usr/bin/core_perl/"}

Since the third item is set to 0, strcpy segfaults at file-find.c:81.
Comment 3 Anatol 2017-06-05 13:20:31 UTC
Hi, any progress with fixing this issue?

Arch users found that 'arduino' tool crashes because of this bug. https://bugs.archlinux.org/task/54159
Comment 4 Bartłomiej Piotrowski 2017-11-22 22:46:39 UTC
Problematic change has been reverted in r253886 and backported to gcc-7-branch. (We also did that downstream in Arch Linux prior the revert.)
Comment 5 Andrew Pinski 2021-12-24 08:48:29 UTC
Even though PR 81829 is newer, it is what is recorded as the bug report in the changelog so closing this one as a dup of bug 81829.

*** This bug has been marked as a duplicate of bug 81829 ***