Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gollvm: failure to build on Arch Linux #36512

Open
Mythra opened this issue Jan 11, 2020 · 12 comments
Open

gollvm: failure to build on Arch Linux #36512

Mythra opened this issue Jan 11, 2020 · 12 comments
Milestone

Comments

@Mythra
Copy link

@Mythra Mythra commented Jan 11, 2020

What operating system and processor architecture are you using (go env)?

x86_64 Arch Linux

$ uname -a
Linux omikron 5.4.10.a-1-hardened #1 SMP PREEMPT Thu, 09 Jan 2020 20:14:59 +0000 x86_64 GNU/Linux

(Failure building go, so I can't run go env, but if there's any more info I'm happy to edit this as need be)

What did you do?

mkdir -p gollvm-workarea
cd gollvm-workarea
git clone https://github.com/llvm/llvm-project.git
cd llvm-project/llvm/tools
git clone https://go.googlesource.com/gollvm
cd gollvm
git clone https://go.googlesource.com/gofrontend
cd libgo
git clone https://github.com/libffi/libffi.git
git clone https://github.com/ianlancetaylor/libbacktrace.git
cd ~/projects/personal/gollvm-workarea/
mkdir -p build.rel && cd build.rel
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_LINKER=gold -G Ninja -DLLVM_TARGETS_TO_BUILD="X86" ../llvm-project/llvm/
ninja gollvm

What did you expect to see?

I expected to be able to build gollvm successfully.

What did you see instead?

Results in: THESE error logs.

After doing some digging I realized it was missing some fields in gen-sysinfo.go, so I manually added in the following fields to the very bottom of the file. Running ninja again then results in: THIS error message. This looks similar to some output posted on #26405 in terms of editing a file, and seeing failure to link to cri.o. As such I'm going to post the two commands requested in that issue in case it's of help:

$ echo "package tiny" > tiny.go
$ ./bin/llvm-goc -v -c tiny.go
gollvm version 1 (experimental) [LLVM version 10]
Candidate GCC install:
version: 9.2.0
foundTriple: x86_64-pc-linux-gnu
libPath: /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0
parentLibPath: /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../..
installPath: /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0
ProgramPaths:
FilePaths:
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0
Target: x86_64-unknown-linux-gnu
 ./bin/llvm-goc -S tiny.go -L/home/cynthia/projects/personal/gollvm-workarea/build.rel/./bin/../lib64 -o /tmp/compile-393cb7.s
 /usr/bin/as --64 -o tiny.o /tmp/compile-393cb7.s
$ clang -c -v himom.c
clang version 9.0.1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/9.2.0
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/9.2.0
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
clang-9: error: no such file or directory: 'himom.c'
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 12, 2020

I don't know much about Arch Linux, but it looks like you don't have the C developer libraries installed.

@Mythra
Copy link
Author

@Mythra Mythra commented Jan 12, 2020

Hmmm Other things seem to find them fine (other C/C++ codebases), and the package manager shows I have libc++/libstdc++/glibc/etc. (I also definetely have crti.o, and the like:

sudo find / -name "crti.o" 2>/dev/null | rg -v gollvm-workarea
/usr/lib/crti.o
/usr/lib32/crti.o

)

Is there anything in particular I should check for that I could be missing? The other issue that has a similar error message seems to come from it improperly recognizing the glibc directory (perhaps I have a setup that is triggering the same behaviour?)

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 12, 2020

That's odd. I don't know what is happening. @thanm is on vacation, but maybe @cherrymui has a quick answer.

@erifan
Copy link
Contributor

@erifan erifan commented Jan 13, 2020

Currently we find crt1.o from /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crt1.o, but on Arch Linux, crt1.o is in directory /usr/lib/, and I didn't even find directory /usr/lib/x86_64-pc-linux-gnu/. My Arch linux environment is pulled from https://hub.docker.com/_/archlinux/. At first it didn't have gcc, I installed it myself. I don't know if this directory exists if Arch Linux is installed from image.

To fix this issue, we may need to add the /usr/lib directory to the Toolchain.filePaths_ when initializing Linux::Linux class.

@Mythra
Copy link
Author

@Mythra Mythra commented Jan 13, 2020

Looks like that worked for the second issue (crt):

$ cd projects/personal/gollvm-workspace/build.rel/
$ vim ../llvm-project/llvm/tools/gollvm/driver/LinuxToolChain.cpp
diff --git a/driver/LinuxToolChain.cpp b/driver/LinuxToolChain.cpp
index dfce121..408e587 100644
--- a/driver/LinuxToolChain.cpp
+++ b/driver/LinuxToolChain.cpp
@@ -71,6 +71,7 @@ Linux::Linux(gollvm::driver::Driver &driver,
                                       "/../" + ftrip).str());
   addIfPathExists(fpaths, llvm::Twine(osLibDir).str());
   addIfPathExists(fpaths, llvm::Twine(osLibDir + "/" + ftrip).str());
+  addIfPathExists(fpaths, llvm::Twine("/usr/lib").str());
 
   // Include program and file paths in verbose output.
   if (driver.args().hasArg(gollvm::options::OPT_v)) {
$ cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_LINKER=gold -G Ninja ../llvm-project/llvm
$ ninja gollvm
# Fails due to errors posted.
$ vim ../build.rel/tools/gollvm/libgo/gen-sysinfo.go
# Add fields mentioned in issue to gen-sysinfo.go
$ ninja gollvm
# Succeeds \o/

I'm happy to file just this change, though if possible I'd also like to figure out why gen-sysinfo.go isn't getting the fields needed so it can just be one PR if possible.

@cagedmantis cagedmantis added this to the Backlog milestone Jan 13, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 13, 2020

If they are different problems then we would certainly prefer different PRs.

@Mythra
Copy link
Author

@Mythra Mythra commented Jan 13, 2020

Fair enough, I'll go ahead and open one for this.

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 13, 2020

Change https://golang.org/cl/214599 mentions this issue: gollvm: add /usr/{lib,lib32} to toolchain paths

@erifan
Copy link
Contributor

@erifan erifan commented Jan 14, 2020

@SecurityInsanity I didn't encounter the issue related to gen-sysinfo.go, I can successfully build gollvm on Arch Linux after solving the crt{1|i|n}.o issue. My container information:

# uname -a
Linux 4b4af198419e 4.15.0-72-generic #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019 x86_64 GNU/Linux

# gcc --version
gcc (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# m4 --version
m4 (GNU M4) 1.4.18
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Rene' Seindal.

# cmake --version
cmake version 3.16.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

# ninja --version
1.9.0

# python --version
Python 3.8.1
@Mythra
Copy link
Author

@Mythra Mythra commented Jan 14, 2020

Hey @erifan , Thanks for that info. I wonder if this is maybe something to do with me using CC=clang, and or the hardned kernel? Those are the two things that look different at a glance. For help here's my info:

$ uname -a
Linux omikron 5.4.10.a-1-hardened #1 SMP PREEMPT Thu, 09 Jan 2020 20:14:59 +0000 x86_64 GNU/Linux

$ env | rg CC
CC=clang

$ env | rg CXX
CXX=clang++

$ clang --version
clang version 9.0.1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ m4 --version
m4 (GNU M4) 1.4.18
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Rene' Seindal.

$ cmake --version
cmake version 3.16.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

$ 1.9.0

$ python --version
Python 3.8.1
@erifan
Copy link
Contributor

@erifan erifan commented Jan 14, 2020

Hmm,,, I don't know, maybe you can have a try with gcc

@gopherbot
Copy link

@gopherbot gopherbot commented Mar 19, 2020

Change https://golang.org/cl/224037 mentions this issue: gollvm: add rudimentary linux distro detection support

pingw33n pushed a commit to pingw33n/gollvm that referenced this issue Oct 6, 2020
Add support to the driver for detecting the linux distribution it is
running on. Different distributions install GCC headers and support
libraries in different places, complicating the process of selecting
the proper -L arguments to the linker. This patch will allow the
driver to look at the host's distro as part of the process of setting
up the library paths.

Updates golang/go#36512.

Change-Id: I90dfc8880096d63f1d36b97e068394d51936fe57
Reviewed-on: https://go-review.googlesource.com/c/gollvm/+/224037
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.