Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.

Bug 1749971

Summary: On x86_64, clang detects the wrong gcc directory
Product: [Fedora] Fedora Reporter: Hans Ulrich Niedermann <rhbugs>
Component: clangAssignee: Tom Stellard <tstellar>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 30CC: airlied, sbergman, sguelton, siddharth.kde, tstellar
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: clang-8.0.0-3.fc30 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1824365 (view as bug list) Environment:
Last Closed: 2019-10-04 21:24:09 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:

Description Hans Ulrich Niedermann 2019-09-07 00:12:26 UTC
Description of problem:

    When clang is supposed to natively link a C program, it picks the gcc installation in /usr/lib/gcc/x86_64-linux-gnu/9 instead of the one in /usr/lib/gcc/x86_64-redhat-linux/9 and fails with "/usr/bin/ld: cannot find -lgcc_s" instead of producing a native executable.

Version-Release number of selected component (if applicable):

    clang-8.0.0-1.fc30.x86_64

    with the following two packages installed

    gcc-9.2.1-1.fc30.x86_64
    gcc-x86_64-linux-gnu-9.1.1-1.fc30.x86_64

How reproducible:

    100%

Steps to Reproduce:
1. dnf -y install clang
2. clang -o basic-main basic-main.c # this works
3. dnf -y install gcc-x86_64-linux-gnu
4. clang -o basic-main basic-main.c # this fails

Actual results:

    /usr/bin/ld: cannot find -lgcc_s
    clang-8: error: linker command failed with exit code 1 (use -v to see invocation)

Expected results:

    No error message, and an executable file to run natively.

Additional info:

### The basic C code example file basic-main.c ###

    #include <stdio.h>

    int main(void)
    {
      printf("basic main program\n");
      return 0;
    }

### The error case with "clang -v -o basic-main basic-main.c" ###

clang version 8.0.0 (Fedora 8.0.0-1.fc30)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
 "/usr/bin/clang-8" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name basic-main.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/lib64/clang/8.0.0 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/8.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/ndim/clang-and-gcc-bug -ferror-limit 19 -fmessage-length 118 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/basic-main-606e4c.o -x c basic-main.c -faddrsig
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib64/clang/8.0.0/include
 /usr/include
End of search list.
 "/usr/bin/ld" --hash-style=gnu --no-add-needed --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o basic-main /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../lib64/crt1.o /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../lib64/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/9 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../lib64 -L/usr/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib /tmp/basic-main-606e4c.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtend.o /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../lib64/crtn.o
/usr/bin/ld: cannot find -lgcc_s
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)

### The success case with "clang -v -o basic-main basic-main.c" ###

clang version 8.0.0 (Fedora 8.0.0-1.fc30)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
 "/usr/bin/clang-8" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name basic-main.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/lib64/clang/8.0.0 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/8.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/ndim/clang-and-gcc-bug -ferror-limit 19 -fmessage-length 118 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/basic-main-aabab6.o -x c basic-main.c -faddrsig
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib64/clang/8.0.0/include
 /usr/include
End of search list.
 "/usr/bin/ld" --hash-style=gnu --no-add-needed --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o basic-main /usr/bin/../lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crt1.o /usr/bin/../lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crti.o /usr/bin/../lib/gcc/x86_64-redhat-linux/9/crtbegin.o -L/usr/bin/../lib/gcc/x86_64-redhat-linux/9 -L/usr/bin/../lib/gcc/x86_64-redhat-linux/9/../../../../lib64 -L/usr/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib/gcc/x86_64-redhat-linux/9/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib /tmp/basic-main-aabab6.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/x86_64-redhat-linux/9/crtend.o /usr/bin/../lib/gcc/x86_64-redhat-linux/9/../../../../lib64/crtn.o

Comment 1 Tom Stellard 2019-09-07 04:21:39 UTC
Pull request: https://src.fedoraproject.org/rpms/clang/pull-request/40

Comment 2 Fedora Update System 2019-09-26 00:10:33 UTC
FEDORA-2019-30920cc6e1 has been submitted as an update to Fedora 30. https://bodhi.fedoraproject.org/updates/FEDORA-2019-30920cc6e1

Comment 3 Fedora Update System 2019-09-27 02:18:48 UTC
clang-8.0.0-3.fc30, llvm-test-suite-8.0.0-3.fc30 has been pushed to the Fedora 30 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-30920cc6e1

Comment 4 Fedora Update System 2019-10-04 21:24:09 UTC
clang-8.0.0-3.fc30, llvm-test-suite-8.0.0-3.fc30 has been pushed to the Fedora 30 stable repository. If problems still persist, please make note of it in this bug report.