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 · 14 comments
Open

gollvm: failure to build on Arch Linux #36512

Mythra opened this issue Jan 11, 2020 · 14 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@Mythra
Copy link

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
Member

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 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
Member

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

@erifan
Copy link

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 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 the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 13, 2020
@cagedmantis cagedmantis added this to the Backlog milestone Jan 13, 2020
@ianlancetaylor
Copy link
Member

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

@Mythra
Copy link
Author

Mythra commented Jan 13, 2020

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

@gopherbot
Copy link
Contributor

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

@erifan
Copy link

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 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

erifan commented Jan 14, 2020

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

@gopherbot
Copy link
Contributor

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

@realqhc
Copy link

realqhc commented Apr 12, 2022

  if (this->distro_ == distro::DistroArchLinux)
    addIfPathExists(fpaths, llvm::Twine("/usr/" + osLibDir).str());

Can we try to mitigate this issue by adding this to Linux::Linux() in LinuxToolChain.cpp, if it seems fine I'm glad to make a submission.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/399317 mentions this issue: gollvm: fix linux distro detection for Arch

lazyparser pushed a commit to plctlab/gollvm that referenced this issue May 7, 2022
The existing detection will wrongly detect Arch Linux as Ubuntu since there is lsb-release as well as arch-release under /etc/. This patch tries to fix it by changing the order of detection.

Updates golang/go#36512.

Change-Id: I3af1a9ce6843e25b47e1db4755e77303d06b33da
Reviewed-on: https://go-review.googlesource.com/c/gollvm/+/399317
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
@seankhliao seankhliao modified the milestones: Backlog, gollvm Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants