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

Link error with gcc 11.2.1 #175

Open
danbev opened this issue Aug 30, 2022 · 10 comments
Open

Link error with gcc 11.2.1 #175

danbev opened this issue Aug 30, 2022 · 10 comments

Comments

@danbev
Copy link
Contributor

danbev commented Aug 30, 2022

I'm seeing the following link error when building locally using the following commands:

$ mkdir build                                                                   
$ cd build                                                                      
$ cmake ..                                                                      
$ make                                                                          
[ 59%] Linking C shared library libuvwasi.so                                    
/usr/bin/ld: _deps/libuv-build/libuv_a.a(random.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
...                                                                             
collect2: error: ld returned 1 exit status                                      
make[2]: *** [CMakeFiles/uvwasi.dir/build.make:210: libuvwasi.so] Error 1          
make[1]: *** [CMakeFiles/Makefile2:196: CMakeFiles/uvwasi.dir/all] Error 2         
make: *** [Makefile:146: all] Error 2

This can be avoided around by setting CMAKE_POSITION_INDEPENDENT_CODE to True:

$ cmake -DCMAKE_POSITION_INDEPENDENT_CODE=True ..

This could also be set in CMakeLists.txt:

set(CMAKE_POSITION_INDEPENDENT_CODE ON)                                         

GCC version:

$ gcc --version
gcc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)

I'm not sure if this is an issue with my local environment, as the CI servers are obviously working as expected. But I wanted to create this issue just in case anyone else runs into it.

@phated
Copy link
Contributor

phated commented Jan 13, 2023

@cjihrig Do we know if the shared library version of uvwasi works? I'm getting linking errors when trying to link uvwasi with wasm-micro-runtime (instead of compiling the sources together).

@cjihrig
Copy link
Collaborator

cjihrig commented Jan 13, 2023

I'm not sure. I didn't work on nor use the shared library version. It was added in d8280df. Maybe @Diatrus knows.

@Diatrus
Copy link
Contributor

Diatrus commented Jan 13, 2023

I'm not sure. I didn't work on nor use the shared library version. It was added in d8280df. Maybe @Diatrus knows.

I currently use the shared version of the uvwasi library when linking with nodejs, and I don't know that anything has changed linking-wise. I'd have to see the error myself. As for the link error above, the shared library should be compiled with -fPIC. If this was a mistake on my part by not adding that, I can look into a PR soon.

@marcopiraccini
Copy link

marcopiraccini commented Feb 1, 2023

I can reproduce the issue with:

➜ gcc --version                             
gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0

...will take a look

@ApsarasX
Copy link

I also encounter this problem.

My compilation environment information is as follows:

  • OS: Ubuntu 20.04.6 LTS
  • Compiler: gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
  • GLIBC: 2.31

@ApsarasX
Copy link

Is there any progress for this issue?

@cjihrig
Copy link
Collaborator

cjihrig commented Jun 15, 2023

@phated do you know if #210 helps with this at all?

@phated
Copy link
Contributor

phated commented Jun 16, 2023

@cjihrig I'm uncertain. I think wamr is doing static linking and I don't know how to build their executable with dynamic linking. My PR definitely enables linking somehow from produced artifacts.

@ApsarasX
Copy link

@cjihrig I'm uncertain. I think wamr is doing static linking and I don't know how to build their executable with dynamic linking. My PR definitely enables linking somehow from produced artifacts.

@phated I compiled standalone uvwasi, rather than linking it with WAMR.

@yagehu
Copy link
Contributor

yagehu commented Dec 5, 2023

You can work around it by adding -fPIC:

cmake ../.. -DBUILD_TESTING=ON -DCMAKE_C_FLAGS=-fPIC

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

7 participants