Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 672036

Summary: sys-devel/llvm: Linking with LLVM includes extra positional arguments in CommandLine library
Product: Gentoo Linux Reporter: Magnus Lång <margnus1>
Component: Current packagesAssignee: LLVM support project <llvm>
Status: RESOLVED OBSOLETE    
Severity: normal CC: davidweb, mgorny
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: Test program to reproduce the bug

Description Magnus Lång 2018-11-26 23:46:32 UTC
Created attachment 556430 [details]
Test program to reproduce the bug

I am having an issue with using LLVM's CommandLine library when linking with LLVM. In particular, an extra positional argument is included in the command line from somewhere.

Here's how to reproduce it. This program is supposed to take a single argument and print it out.

  $ cat gentoo-llvm-repro.cpp
  #include <llvm/Support/CommandLine.h>
  #include <iostream>
  llvm::cl::opt<std::string> cl_input(llvm::cl::desc("<actual input file>"),
    llvm::cl::Positional, llvm::cl::init("-"));
  int main(int argc, char *argv[]){
    llvm::cl::ParseCommandLineOptions(argc, argv);
    std::cout << cl_input << "\n";
    return 0;
  }
  $ g++ $(lvm-config --cxxflags --libs --ldflags) gentoo-llvm-repro.cpp

Actual:

  $ ./a.out --help | head -1
  USAGE: a.out [options] <input file> <actual input file>
  $ ./a.out asd
  -
  $ ./a.out asd asd
  asd

Expected:

  $ ./a.out --help | head -1
  USAGE: a.out [options] <actual input file>
  $ ./a.out asd
  asd
  $ ./a.out asd asd
  a.out: Too many positional arguments specified!
  Can specify at most 1 positional arguments: See: ./a.out -help

Affected versions:

All I have tried, 4.0.1-r1, 5.0.2, 6.0.1-r2, 7.0.1_rc2, 9999 (from 2018-11-22)
Comment 1 David Klaftenegger 2018-11-27 23:29:43 UTC
I can confirm that this happens on my system, using =sys-devel/llvm-5.0.1.

It happens independently of whether I compile the test program using g++ or clang++, indicating the bug is indeed in llvm (or the gentoo package thereof) and not the compiler used.
Comment 2 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2018-11-28 11:29:14 UTC
I suppose you aren't supposed to link *all* of LLVM libraries like this.  If I limit it to 'llvm-config ... support', it works just fine.  You may try going through 'llvm-config --components' to see which one breaks it.
Comment 3 Magnus Lång 2018-11-28 13:09:03 UTC
It seems to be caused by including the "tablegen" component.

However, even with "llvm-config ... support tablegen --ignore-libllvm", I have not been able to reproduce it on any other distribution (I have tried Debian, Ubuntu, FreeBSD-11 (on these, using CommandLine but not linking with libllvm seems to be broken, so clearly linking with all the components is the most common way "in the wild"), and Arch so far), or when building from source.
Comment 4 Magnus Lång 2018-11-28 13:28:30 UTC
I spoke too soon about linking with a subset of libraries being broken in Debian, Ubuntu, and FreeBSD. I was able to get that working. However, none of them exhibit the behaviour of Gentoo's LLVM.
Comment 5 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2020-05-01 09:18:53 UTC
Mass-closing bugs reported for removed LLVM versions.  Feel free to reopen if the issue still applies and there is no newer report for it.