jpsim / Yams

A Sweet and Swifty YAML parser.
https://jpsim.com/Yams
MIT License
1.12k stars 144 forks source link

Build CYaml as PIC explicitly to link it agaist libYams.so #353

Closed kateinoigakukun closed 2 years ago

kateinoigakukun commented 2 years ago

CYaml has been a private dependency of libYams.so and linked statically against it since 2a93d740efde7caa4bc1e74c4e3c91361c12167b. 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.

jpsim commented 2 years ago

Do you need me to tag a new release with this change?

kateinoigakukun commented 2 years ago

@jpsim Thank you for the quick merge! It would be appreciated if we can have a new release 🙏

jpsim commented 2 years ago

https://github.com/jpsim/Yams/releases/tag/5.0.1

kateinoigakukun commented 2 years ago

Thank you 😄