Skip to content

Clang link time optimization not working on OSX #19098

@dipinhora

Description

@dipinhora

Issue description

The example for Clang's Link Time Optimization (http://llvm.org/docs/LinkTimeOptimization.html#example-of-link-time-optimization) doesn't work in nix on OSX. I tested with clang versions 3.8.0, 3.7.1, and 3.6.2. I wasn't able to test with clang 3.9.0 because of an error compiling llvm-3.9.0.

It fails with the following on OSX with Clang 3.7.1:

[nix-shell:~/tmp]$ clang --version
clang version 3.7.1 (tags/RELEASE_371/final)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
[nix-shell:~/tmp]$ clang -flto a.o main.o -o main
ld: warning: ignoring file a.o, file was built for unsupported file format ( 0xDE 0xC0 0x17 0x0B 0x00 0x00 0x00 0x00 0x14 0x00 0x00 0x00 0xFC 0x06 0x00 0x00 ) which is not the architecture being linked (x86_64): a.o
Undefined symbols for architecture x86_64:
  "_foo1", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang-3.7: error: linker command failed with exit code 1 (use -v to see invocation)

It fails with the following on OSX with Clang 3.8.0:

[nix-shell:~/tmp]$ clang --version
clang version 3.8.0 (tags/RELEASE_380/final)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
InstalledDir: /nix/store/w440mfm2abkxyaw7j86pmhbkj680118d-clang-3.8.0/bin
[nix-shell:~/tmp]$ clang -flto a.o main.o -o main
clang-3.8: warning: libLTO.dylib relative to clang installed dir not found; using 'ld' default search path instead
ld: warning: ignoring file a.o, file was built for unsupported file format ( 0xDE 0xC0 0x17 0x0B 0x00 0x00 0x00 0x00 0x14 0x00 0x00 0x00 0x94 0x09 0x00 0x00 ) which is not the architecture being linked (x86_64): a.o
Undefined symbols for architecture x86_64:
  "_foo1", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)

Steps to reproduce

On an OSX machine:
Install nix: curl https://nixos.org/nix/install | sh
Run (for clang 3.8.0): nix-shell --pure -p llvmPackages_38.clang
Run (for clang 3.7.1): nix-shell --pure -p llvmPackages_37.clang
In shell: Follow instructions at http://llvm.org/docs/LinkTimeOptimization.html#example-of-link-time-optimization to test link time optimization with the example code.

Technical details

  • System: Mac OSX 10.10.5; Output of uname -a:
Darwin Dipins-MBP.home 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
  • Nix version: nix-env (Nix) 1.11.4
  • Nixpkgs version: "17.03pre91937.5cda2be"

Metadata

Metadata

Assignees

No one assigned

    Labels

    6.topic: darwinRunning or building packages on Darwin6.topic: llvm/clangIssues related to llvmPackages, clangStdenv and related

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions