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

relocation R_X86_64_PC32 cannot be used against symbol internal/cpu.options #30891

Closed
helperShang opened this issue Mar 17, 2019 · 8 comments
Closed
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@helperShang
Copy link

go version ubuntu 18.04

go version go1.12 linux/amd64

go env

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xm/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/xm/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go-1.12"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.12/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build519519221=/tmp/go-build -gno-record-gcc-switches"

go build -buildmode=c-archive -o wasm.a // this is ok
when i use cmake build error

ld: error: relocation R_X86_64_PC32 cannot be used against symbol internal/cpu.options; recompile with -fPIC
>>> defined in ../lib/linux/wasm.a(go.o)
>>> referenced by cpu.go:195 (/usr/lib/go-1.12/src/internal/cpu/cpu.go:195)
>>>               go.o:(local.internal/cpu.processOptions) in archive ../lib/linux/wasm.a
@ianlancetaylor
Copy link
Contributor

What is the actual compiler or linker command that is failing? What C linker are you using?

@helperShang
Copy link
Author

@ianlancetaylor gcc
C linker ,I use llvm lld and gcc ld

@ianlancetaylor
Copy link
Contributor

What is the actual compiler or linker command that is failing?

@helperShang
Copy link
Author

all fail

@helperShang
Copy link
Author

mac ok

@katiehockman katiehockman added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 19, 2019
@katiehockman
Copy link
Contributor

@helperShang Can you be more specific about the commands you are running with the full output of the command execution?

@ianlancetaylor added the WaitingForInfo tag since it doesn't sound like we have enough information yet, but please remove it if you feel that you have enough information to resolve this.

@helperShang
Copy link
Author

@katiehockman
cmake

cmake_minimum_required(VERSION 3.10)
project(wasm_java)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES VM.cpp jni_wrap.cxx)

#add jhi include
find_package(JNI)
if (JNI_FOUND)
    INCLUDE_DIRECTORIES(${JNI_INCLUDE_DIRS})
elseif (JNI_INCLUDE)
    INCLUDE_DIRECTORIES(${JNI_INCLUDE})
endif ()
FIND_PACKAGE(SWIG)
if (SWIG_FOUND)
    MESSAGE(STATUS ${SWIG_EXECUTABLE})
endif ()

IF (WIN32)
    MESSAGE(STATUS "Now is windows")
    SET(WASM_OS_DIR windows)
    SET(WASM_OS_LIB wasm.lib)
ELSEIF (APPLE)
    SET(WASM_OS_DIR darwin)
    SET(WASM_OS_LIB wasm.a)
    MESSAGE(STATUS "Now is Apple systens.")
ELSEIF (UNIX)
    MESSAGE(STATUS "Now is UNIX-like OS's. Including aPPLE os x  and CygWin")
    set(WASM_OS_DIR linux)
    set(WASM_OS_LIB wasm.a)
ENDIF ()

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/${WASM_OS_DIR})
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/${WASM_OS_DIR})
ADD_LIBRARY(VM SHARED ${SOURCE_FILES})

if (APPLE OR UNIX)
    ADD_LIBRARY(bar SHARED IMPORTED)
    SET_TARGET_PROPERTIES(
            bar
            PROPERTIES IMPORTED_LOCATION
            ${CMAKE_SOURCE_DIR}/lib/${WASM_OS_DIR}/${WASM_OS_LIB}
    )
    TARGET_LINK_LIBRARIES(VM bar)
elseif (WIN32)
	# TARGET_LINK_LIBRARIES(VM ${WASM_OS_LIB})
endif ()

make info

/usr/bin/cmake -H/home/wmt/wasm-lib-jni -B/home/wmt/wasm-lib-jni/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/wmt/wasm-lib-jni/build/CMakeFiles /home/wmt/wasm-lib-jni/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/wmt/wasm-lib-jni/build'
make -f CMakeFiles/VM.dir/build.make CMakeFiles/VM.dir/depend
make[2]: Entering directory '/home/wmt/wasm-lib-jni/build'
cd /home/wmt/wasm-lib-jni/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/wmt/wasm-lib-jni /home/wmt/wasm-lib-jni /home/wmt/wasm-lib-jni/build /home/wmt/wasm-lib-jni/build /home/wmt/wasm-lib-jni/build/CMakeFiles/VM.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/wmt/wasm-lib-jni/build'
make -f CMakeFiles/VM.dir/build.make CMakeFiles/VM.dir/build
make[2]: Entering directory '/home/wmt/wasm-lib-jni/build'
[ 33%] Linking CXX shared library libVM.so
/usr/bin/cmake -E cmake_link_script CMakeFiles/VM.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC -O3 -DNDEBUG  -shared -Wl,-soname,libVM.so -o libVM.so CMakeFiles/VM.dir/VM.cpp.o CMakeFiles/VM.dir/jni_wrap.cxx.o  -L/home/wmt/wasm-lib-jni/lib/linux -Wl,-rpath,/home/wmt/wasm-lib-jni/lib/linux ../lib/linux/wasm.a 
/usr/bin/ld: ../lib/linux/wasm.a(go.o): relocation R_X86_64_PC32 against symbol `internal/cpu.options' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
CMakeFiles/VM.dir/build.make:124: recipe for target 'libVM.so' failed
make[2]: *** [libVM.so] Error 1
make[2]: Leaving directory '/home/wmt/wasm-lib-jni/build'
CMakeFiles/Makefile2:70: recipe for target 'CMakeFiles/VM.dir/all' failed
make[1]: *** [CMakeFiles/VM.dir/all] Error 2
make[1]: Leaving directory '/home/wmt/wasm-lib-jni/build'
Makefile:86: recipe for target 'all' failed
make: *** [all] Error 2

@ianlancetaylor
Copy link
Contributor

There is no current support for using -buildmode=c-archive to build a Go object and to link that Go object into a shared library.

I believe you can get it to work if you link the shared object with -Bsymbolic. That is, something like:

/usr/bin/c++ -fPIC -O3 -DNDEBUG  -shared -Wl,-Bsymbolic -Wl,-soname,libVM.so -o libVM.so CMakeFiles/VM.dir/VM.cpp.o CMakeFiles/VM.dir/jni_wrap.cxx.o  -L/home/wmt/wasm-lib-jni/lib/linux -Wl,-rpath,/home/wmt/wasm-lib-jni/lib/linux ../lib/linux/wasm.a

However, note that -Bsymbolic will affect the non-Go code as well, and you must make sure that those effects will work for your case.

I'm going to close this because you're trying to do something that is not supported and there is no reasonable chance that it will be supported in the future. Sorry.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants