ui icon indicating copy to clipboard operation
ui copied to clipboard

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

Open arisbasic opened this issue 7 years ago • 42 comments

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

arisbasic avatar Mar 03 '17 13:03 arisbasic

What version of Go?

andlabs avatar Mar 03 '17 19:03 andlabs

go 1.8

arisbasic avatar Mar 03 '17 20:03 arisbasic

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.

mjyut avatar Mar 25 '17 18:03 mjyut

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

andlabs avatar Mar 25 '17 22:03 andlabs

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

mjyut avatar Mar 26 '17 04:03 mjyut

And what happens if you run

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

instead?

Source

andlabs avatar Mar 26 '17 06:03 andlabs

(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

mjyut avatar Mar 26 '17 07:03 mjyut

same problem with @arisbasic Manjaro latest stable Go 1.8.3

worked around with @mjyuta 's solution

bruceauyeung avatar Jun 10 '17 02:06 bruceauyeung

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

jrmiller82 avatar Jul 21 '17 20:07 jrmiller82

And yes, following the above solution worked.

jrmiller82 avatar Jul 21 '17 20:07 jrmiller82

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

jkahrs avatar Aug 03 '17 10:08 jkahrs

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.

penguwin avatar Feb 05 '18 21:02 penguwin

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

andlabs avatar Feb 05 '18 22:02 andlabs

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

virtualsue avatar Mar 25 '18 21:03 virtualsue

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

andlabs avatar Mar 25 '18 21:03 andlabs

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.

andlabs avatar Mar 26 '18 21:03 andlabs

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.

tapir avatar Mar 29 '18 14:03 tapir

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

alex73 avatar May 11 '18 08:05 alex73

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

andlabs avatar May 11 '18 11:05 andlabs

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 ?

TechComSpot avatar May 26 '18 11:05 TechComSpot

You never set your $GOPATH.

andlabs avatar May 26 '18 13:05 andlabs

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

TechComSpot avatar May 26 '18 17:05 TechComSpot

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.

andlabs avatar May 26 '18 18:05 andlabs

@andlabs thank you.

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

Thanks!

TechComSpot avatar May 27 '18 04:05 TechComSpot

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.

andlabs avatar May 27 '18 04:05 andlabs

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

TechComSpot avatar May 27 '18 05:05 TechComSpot

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.

andlabs avatar May 27 '18 05:05 andlabs

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

TechComSpot avatar May 27 '18 11:05 TechComSpot

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

andlabs avatar May 27 '18 14:05 andlabs

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

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

Please, Help!

TechComSpot avatar Jun 05 '18 08:06 TechComSpot