Skip to content

libui_linux_amd64.a(libui-combined.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC #230

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

Open
arisbasic opened this issue Mar 3, 2017 · 42 comments

Comments

@arisbasic
Copy link

go get -u github.com/andlabs/ui

github.com/andlabs/ui

/usr/bin/ld: ../../go/src/github.com/andlabs/ui/libui_linux_amd64.a(libui-combined.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

@andlabs
Copy link
Owner

andlabs commented Mar 3, 2017

What version of Go?

@arisbasic
Copy link
Author

go 1.8

@mjyut
Copy link

mjyut commented Mar 25, 2017

My environment (Ubuntu 16.10 64bit) has the same problem.
This problem was solved by building libui_linux_amd64.a in my own environment.
(I do not know why)

My environment 🖥️

$ uname -a
Linux rex 4.8.0-41-generic #44-Ubuntu SMP Fri Mar 3 15:27:17 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ go version
go version go1.8 linux/amd64
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mjy/lib/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build041059720=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What problem 😦

$ go get -v github.com/andlabs/ui
github.com/andlabs/ui (download)
github.com/andlabs/ui
# github.com/andlabs/ui
/usr/bin/ld: lib/go/src/github.com/andlabs/ui/libui_linux_amd64.a(libui-combined.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

How to solve it 🙂

# build `libui`
git clone [email protected]:andlabs/libui.git
cd libui/
mkdir build
cd build/
cmake -DBUILD_SHARED_LIBS=OFF ..
make

# copy to `ui` src dir
cp out/libui.a ${GOPATH}/src/github.com/andlabs/ui/libui_linux_amd64.a

# build `ui`
cd ${GOPATH}/src/github.com/andlabs/ui/
go build

Successful build. The tutorial code also worked.

@andlabs
Copy link
Owner

andlabs commented Mar 25, 2017

So what is the difference between my .a (built with Ubuntu 15.10 or 16.04, I forget which) and yours? If we can figure that out, we can nail what's going on...

@mjyut
Copy link

mjyut commented Mar 26, 2017

It is not certain but "Relocation Types" seems to be different. (I do not know what this means)

in git repository binary

There are many R_X86_64_32S in relocation type.

$ readelf -r libui_git_binary.a |grep R_X86_64_32S |wc -l   # Many
288
$ readelf -r libui_git_binary.a |head

File: libui_git_binary.a(libui-combined.o)

Relocation section '.rela.text' at offset 0x5a1a0 contains 2046 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
0000000001c0  00020000000b R_X86_64_32S      0000000000000000 .rodata + 0
0000000001d8  00020000000b R_X86_64_32S      0000000000000000 .rodata + 8
0000000001fe  00020000000b R_X86_64_32S      0000000000000000 .rodata + 0
000000000221  00020000000b R_X86_64_32S      0000000000000000 .rodata + 340
000000000239  00020000000b R_X86_64_32S      0000000000000000 .rodata + 348

The same error occurs even with a simple build of gcc.

$ gcc main.c libui_git_binary.a $(pkg-config --libs gtk+-3.0) -lm -ldl
/usr/bin/ld: libui_git_binary.a(libui-combined.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

in my build

There is no R_X86_64_32S.

$ readelf -r libui_own_build.a |grep R_X86_64_32S |wc -l   # Nothing
0
$ readelf -r libui_own_build.a |head

File: libui_own_build.a(libui-combined.o)

Relocation section '.rela.text' at offset 0xa43c8 contains 2143 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000195  000200000002 R_X86_64_PC32     0000000000000000 .rodata - 4
0000000001b2  000200000002 R_X86_64_PC32     0000000000000000 .rodata + 4
0000000001dd  000200000002 R_X86_64_PC32     0000000000000000 .rodata - 4
000000000205  000200000002 R_X86_64_PC32     0000000000000000 .rodata + 33c
000000000222  000200000002 R_X86_64_PC32     0000000000000000 .rodata + 344

@andlabs
Copy link
Owner

andlabs commented Mar 26, 2017

And what happens if you run

ar -x file.a  
readelf --relocs libui_combined.o | egrep '(GOT|PLT|JU?MP_SLOT)'

instead?

Source

@mjyut
Copy link

mjyut commented Mar 26, 2017

(GOT|PLT|JU?MP_SLOT) does not match in git repository binary.

$ readelf --relocs libui-combined_git_binary.o | egrep '(GOT|PLT|JU?MP_SLOT)'   # Nothing

In my own build, it matches a lot.

$ readelf --relocs libui-combined_own_build.o | egrep '(GOT|PLT|JU?MP_SLOT)' |wc -l   # Many
1705
$ readelf --relocs libui-combined_own_build.o | egrep '(GOT|PLT|JU?MP_SLOT)' |head
0000000003ec  021e00000004 R_X86_64_PLT32    0000000000000b94 uiAlloc - 4
00000000045e  01f800000004 R_X86_64_PLT32    0000000000000686 _userbug - 4
00000000046a  021000000004 R_X86_64_PLT32    0000000000000cf9 uiFree - 4
0000000004ba  01f800000004 R_X86_64_PLT32    0000000000000686 _userbug - 4
000000000513  01f800000004 R_X86_64_PLT32    0000000000000686 _userbug - 4
000000000552  020100000004 R_X86_64_PLT32    000000000000059c _implbug - 4
000000000668  020500000004 R_X86_64_PLT32    00000000000078c9 realbug - 4
000000000680  02f000000004 R_X86_64_PLT32    0000000000000000 __stack_chk_fail - 4
000000000752  020500000004 R_X86_64_PLT32    00000000000078c9 realbug - 4
00000000076a  02f000000004 R_X86_64_PLT32    0000000000000000 __stack_chk_fail - 4

@bruceauyeung
Copy link

same problem with @arisbasic
Manjaro latest stable
Go 1.8.3

worked around with @mjyuta 's solution

@jrmiller82
Copy link

Same with debian unstable, Go 1.8.3. About to try the solution to build libui on my own.

@jrmiller82
Copy link

And yes, following the above solution worked.

@jkahrs
Copy link

jkahrs commented Aug 3, 2017

Same problem with go 1.8.3 on Arch Linux.
Following the instructions by @mjyuta seems to fix the issue for me.

@penguwin
Copy link

penguwin commented Feb 5, 2018

Also having this issue here on Arch and on a quite vanilla Manjaro with go version 1.9.3.
Following the instructions by @mjyuta (thanks for that) fixed the issue here on both machines for me too.

@andlabs
Copy link
Owner

andlabs commented Feb 5, 2018

Okay, so I will need to fix libui to use PIC everywhere, though I thought I was already doing that?...

@virtualsue
Copy link

virtualsue commented Mar 25, 2018

I'm on debian 9, go 1.10. I've tried the wonderfully detailed workaround from @mjyuta but this is how it ends up:

sue@xray:~/dev/src/github.com/andlabs/ui$ go build
--# github.com/andlabs/ui
/tmp/go-build261791566/b001/_x010.o: In function newFont': ./draw.go:88: undefined reference to uiDrawLoadClosestFont'
/tmp/go-build261791566/b001/_x010.o: In function _cgo_2fc1135dc6ba_Cfunc_uiDrawFontFamiliesFamily': /tmp/go-build/cgo-gcc-prolog:327: undefined reference to uiDrawFontFamiliesFamily'
/tmp/go-build261791566/b001/_x010.o: In function _cgo_2fc1135dc6ba_Cfunc_uiDrawFontFamiliesNumFamilies': /tmp/go-build/cgo-gcc-prolog:344: undefined reference to uiDrawFontFamiliesNumFamilies'
/tmp/go-build261791566/b001/_x010.o: In function _cgo_2fc1135dc6ba_Cfunc_uiDrawListFontFamilies': /tmp/go-build/cgo-gcc-prolog:408: undefined reference to uiDrawListFontFamilies'
/tmp/go-build261791566/b001/_x010.o: In function _cgo_2fc1135dc6ba_Cfunc_uiDrawTextFontHandle': /tmp/go-build/cgo-gcc-prolog:744: undefined reference to uiDrawTextFontHandle'
/tmp/go-build261791566/b001/_x010.o: In function _cgo_2fc1135dc6ba_Cfunc_uiDrawFreeFontFamilies': /tmp/go-build/cgo-gcc-prolog:358: undefined reference to uiDrawFreeFontFamilies'
/tmp/go-build261791566/b001/_x010.o: In function _cgo_2fc1135dc6ba_Cfunc_uiDrawFreeTextFont': /tmp/go-build/cgo-gcc-prolog:382: undefined reference to uiDrawFreeTextFont'
/tmp/go-build261791566/b001/_x010.o: In function _cgo_2fc1135dc6ba_Cfunc_uiDrawTextFontGetMetrics': /tmp/go-build/cgo-gcc-prolog:729: undefined reference to uiDrawTextFontGetMetrics'
/tmp/go-build261791566/b001/_x010.o: In function _cgo_2fc1135dc6ba_Cfunc_uiDrawTextLayoutSetWidth': /tmp/go-build/cgo-gcc-prolog:773: undefined reference to uiDrawTextLayoutSetWidth'
collect2: error: ld returned 1 exit status

@andlabs
Copy link
Owner

andlabs commented Mar 25, 2018

You will need to use the alpha 3.1 or 3.5 source archives, not master.

@andlabs andlabs closed this as completed Mar 26, 2018
@andlabs andlabs reopened this Mar 26, 2018
@andlabs andlabs changed the title go get fails on Linux Manjaro go 1.8 libui_linux_amd64.a(libui-combined.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC Mar 26, 2018
This was referenced Mar 26, 2018
@andlabs
Copy link
Owner

andlabs commented Mar 26, 2018

Okay, so I think andlabs/libui#308 has something to do with it. My HYPOTHESIS is that -fPIC isn't being passed to the extra kludge hack step when building the static library. But I want to get rid of that kludge altogether.

I have another HYPOTHESIS that this is the same issue that prevented me from being able to build a linux/386 version of Alpha 3.5 (which is part of the reason why I didn't migrate the APIs over yet).

If anyone decides to confirm either of these hypotheses in the meantime, then great. Otherwise, we'll see what happens.

@tapir
Copy link

tapir commented Mar 29, 2018

Same here on arch linux with latest Go.
I've installed libui from AUR and using -lui to link Go wrapper. It works that way.

@alex73
Copy link

alex73 commented May 11, 2018

Same with Ubuntu 18.04:
$ go version
go version go1.10.1 linux/amd64
$ go build
# github.com/andlabs/ui
/usr/bin/x86_64-linux-gnu-ld: /home/alex/go/src/github.com/andlabs/ui/libui_linux_amd64.a(libui-combined.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

@andlabs
Copy link
Owner

andlabs commented May 11, 2018

Barring the specific PRs I'm waiting for updates on being completed, I'll try getting rid of libui-combined.o from GTK+ tonight (already did it on OS X). It won't completely fix the libui issue I linked above (there are some runtime-object-system namespace issues I have to work out first), but it will get us 90% of the way there.

Whether that will fix this issue, though, will have to wait a bit longer, because the APIs have changed considerably enough since the last "stable" release that backporting will be totally nontrivial. Alpha 4 may come sooner than I originally planned (I've already forgotten the complete list of what I wanted out of it).

@TechComSpot
Copy link

Hi.

Thanks to @mjyut for sharing the workaround but I did:

build libui

git clone [email protected]:andlabs/libui.git
cd libui/
mkdir build
cd build/
cmake -DBUILD_SHARED_LIBS=OFF ..
make

copy to ui src dir

cp out/libui.a ${GOPATH}/src/github.com/andlabs/ui/libui_linux_amd64.a

and got erorr:

cp: cannot create regular file '/src/github.com/andlabs/ui/libui_linux_amd64.a': No such file or directory
screenshot at 2018-05-26 11-42-56

Please advice where is my fault here ?

@andlabs
Copy link
Owner

andlabs commented May 26, 2018

You never set your $GOPATH.

@TechComSpot
Copy link

@andlabs sorry noob like me.

I reattached correct screenshot.

screenshot at 2018-05-26 17-47-41
But error still appear "No such file or directory"

@andlabs
Copy link
Owner

andlabs commented May 26, 2018

No need to use sudo to copy that into your home folder. The problem now appears to be that one of the directories on the way to your destination is missing. Can you try running ls on every directory in /home/user/GoMobile/src/github.com/andlabs/ui to see which one doesn't exist? That is, start with ls /home/user/GoMobile, then ls /home/user/GoMobile/src, and so on.

@TechComSpot
Copy link

@andlabs thank you.

andlabs directory and ui directory were missing - I created them and cp works.

Thanks!

@andlabs
Copy link
Owner

andlabs commented May 27, 2018

It seems like you did a go get to the default $GOPATH. I forget where the documentation is on that, but it is a thing now.

@TechComSpot
Copy link

TechComSpot commented May 27, 2018

I was able to cp but the last step

build ui

cd ${GOPATH}/src/github.com/andlabs/ui/
go build

screenshot at 2018-05-27 05-10-17

Not works :(

Same for main.go example file
screenshot at 2018-05-27 05-12-14

@andlabs
Copy link
Owner

andlabs commented May 27, 2018

Again, you didn't set your $GOPATH correctly the first time, so Go chose one by default. Unset your $GOPATH, then run go env. It'll tell you what $GOPATH it set the first time you ran go get. Copy the new .a file there, and try again.

@TechComSpot
Copy link

TechComSpot commented May 27, 2018

@andlabs I did next:

  1. Reboot my usb-live debian (Parrot Security) system.
  2. Set up GOPATH and PATH.
  3. Install Golang.
  4. go get -v github.com/andlabs/ui

I got:
screenshot at 2018-05-27 11-15-40
5. I search gtk+ . . . in repository
6. Install something with name like gtk3+

But error still present

Now I got "No package found" instead of "Nonrepresentable section on output
collect2: error: ld returned 1 exit status"

@andlabs
Copy link
Owner

andlabs commented May 27, 2018

For debian the package is called libgtk-3-dev.

@TechComSpot
Copy link

TechComSpot commented Jun 5, 2018

Hi,
@andlabs
did all steps but at the final one go build I got

screenshot at 2018-06-05 11-24-24

Please, Help!

@andlabs
Copy link
Owner

andlabs commented Jun 5, 2018

That's because package ui hasn't been updated to use the latest libui APIs yet. It won't until the next tagged release is made. Until then, you'll have to go back and build the alpha3.5 tag of libui or whatever the latest tag was (I forget now).

@TechComSpot
Copy link

@andlabs thank you for answer.
Can you share the link with the any guide how to do that, please ?

@andlabs
Copy link
Owner

andlabs commented Jun 5, 2018

The same way you did above, except before running cmake, git checkout alpha3.5 or whatever the tag name is.

@TechComSpot
Copy link

@andlabs I did all steps and even GO BUILD works but can't figure out how to run go example described on wiki :(
Can you advice please what I missed?

@andlabs
Copy link
Owner

andlabs commented Jun 12, 2018

Now that go build works, use go install to make it available to other packages.

@TechComSpot
Copy link

TechComSpot commented Jun 12, 2018

@andlabs thank you.
Example from wiki works.
Great job!
Will continue exploring it :)

@TechComSpot
Copy link

@andlabs is it possible to run this library with golang.org/x/mobile/app package which allows go to build android apk?
Sorry for the wrong thread.

@andlabs
Copy link
Owner

andlabs commented Jun 14, 2018

No, there is no support in libui for Android, and I'm not sure if doing that would be the right thing to do, or if a separate API for mobile apps would be better.

@TechComSpot
Copy link

TechComSpot commented Jun 14, 2018

@andlabs thank you for your answer.
Very sad because that's what I'm looking for. :(

@andydotxyz
Copy link

andydotxyz commented Aug 15, 2018

This is still a problem on Arch linux amd64 and go 1.10.3 - trying to work around it by recompiling libui as suggested.

$ go get github.com/andlabs/ui
# github.com/andlabs/ui
/usr/bin/ld: ../../../../andlabs/ui/libui_linux_amd64.a(libui-combined.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

@philiplb philiplb mentioned this issue Aug 29, 2018
@andlabs
Copy link
Owner

andlabs commented Jan 4, 2019

@andydotxyz you are still building an old version of package ui; use go get -u or manually git pull the existing package ui folder in your GOPATH

Everyone else: does this still happen?

@asbjorn
Copy link

asbjorn commented Feb 21, 2019

Using the go get -u instead of just go get solved this issue for me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests