Skip to content

Commit cd43968

Browse files
Build CYaml as PIC explicitly to link it agaist libYams.so (jpsim#353)
CYaml has been a private dependency of libYams.so and linked statically against it since 2a93d74. Therefore, CYaml should be built as PIC, but it wasn't. Since gas 2.31 (Ubuntu 20.04), which includes implicit promotion of non-PIC reloc (R_X86_64_PC32) to PIC reloc (R_X86_64_PLT32)[^1], this issue is not revealed. However gas older than 2.31 (Ubuntu 18.04), this PIC-ness mismatch causes linking failure with the following output: ``` /usr/bin/ld.gold: error: lib/libCYaml.a(api.c.o): requires dynamic R_X86_64_PC32 reloc against 'yaml_realloc' which may overflow at runtime; recompile with -fPIC /usr/bin/ld.gold: error: lib/libCYaml.a(scanner.c.o): requires dynamic R_X86_64_PC32 reloc against 'yaml_parser_fetch_more_tokens' which may overflow at runtime; recompile with -fPIC ``` This patch fixes the PIC-ness mismatch by enabling `POSITION_INDEPENDENT_CODE` explicitly, and adds CI job to check cmake build system works on Ubuntu 18.04. [^1]: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bd7ab16b4537788ad53521c45469a1bdae84ad4a
1 parent a8af498 commit cd43968

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

.github/workflows/cmake.yml

+17
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,20 @@ jobs:
5555
- run: cmake --build build
5656
- run: cmake --build build --target install
5757
- run: file /usr/local/lib/swift/macosx/libYams.dylib | grep "Mach-O 64-bit dynamically linked shared library x86_64"
58+
59+
CMake_Linux:
60+
strategy:
61+
matrix:
62+
tag: ['5.6-focal', '5.6-bionic']
63+
runs-on: ubuntu-latest
64+
container:
65+
image: swift:${{ matrix.tag }}
66+
steps:
67+
- uses: actions/checkout@v2
68+
- run: apt-get update && apt-get install ninja-build curl
69+
- run: curl -L https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-linux-x86_64.tar.gz | tar xz --strip-components=1 -C /usr
70+
- run: swift -version
71+
- run: rm -rf build
72+
- run: cmake -B build -G Ninja -S . -DCMAKE_BUILD_TYPE=Release
73+
- run: cmake --build build
74+
- run: cmake --build build --target install

Sources/CYaml/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ target_include_directories(CYaml PUBLIC
1313
target_compile_options(CYaml PUBLIC
1414
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -DYAML_DECLARE_STATIC>"
1515
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -I${CMAKE_CURRENT_SOURCE_DIR}/include>")
16+
set_property(TARGET CYaml PROPERTY POSITION_INDEPENDENT_CODE ON)
1617

1718
set_property(GLOBAL APPEND PROPERTY YAMS_EXPORTS CYaml)

0 commit comments

Comments
 (0)