Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 672036 - sys-devel/llvm: Linking with LLVM includes extra positional arguments in CommandLine library
Summary: sys-devel/llvm: Linking with LLVM includes extra positional arguments in Comm...
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: LLVM support project
Depends on:
Reported: 2018-11-26 23:46 UTC by Magnus Lång
Modified: 2018-11-28 13:28 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---

Test program to reproduce the bug (gentoo-llvm-repro.cpp,330 bytes, text/x-c++src)
2018-11-26 23:46 UTC, Magnus Lång

Note You need to log in before you can comment on or make changes to this 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


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


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