Skip to content

FindPackage in CMake may mix Lua versions #35

@Buristan

Description

@Buristan

I have the following Lua versions installed on my machine:

tree /usr/include/lua*
/usr/include/lua5.1
├── lauxlib.h
├── luaconf.h
├── lua.h
├── lua.hpp
└── lualib.h
/usr/include/lua5.4
├── lauxlib.h
├── luaconf.h
├── lua.h
├── lua.hpp
└── lualib.h
/usr/include/luajit-2.1
├── lauxlib.h
├── luaconf.h
├── lua.h
├── lua.hpp
├── luajit.h
└── lualib.h

ls /usr/lib64/ | grep lua
liblua5.1.so
liblua5.1.so.0
liblua5.1.so.0.0.0
liblua5.4.so
liblua5.4.so.0
liblua5.4.so.0.0.0
libluajit-5.1.so
libluajit-5.1.so.2
libluajit-5.1.so.2.1.1716656478

The mixed part is the custom mutator library, which uses lua_objlen() which is renamed to the lua_rawlen() since Lua 5.2.

As I noticed, when I build luzer like the following:

cmake -S . -B build -DENABLE_TESTING=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++

It finds the Lua header for the 5.1 version but links with the version 5.4.

As a result, the custom mutator library can't be preloaded:

LD_PRELOAD="/home/burii/reviews/ligurio-luzer/ligurio-luzer/build/luzer/libcustom_mutator.so.1" ls
ls: symbol lookup error: /home/burii/reviews/ligurio-luzer/ligurio-luzer/build/luzer/libcustom_mutator.so.1: undefined symbol: lua_objlen

It results in the following test failures when run by Lua 5.4 binary:

$ ctest -V --test-dir build -R luzer_custom_mutator_example
...
7: /usr/bin/lua5.4: ...burii/reviews/ligurio-luzer/ligurio-luzer/luzer/init.lua:48: function LLVMFuzzerCustomMutator is not available
7: stack traceback:
7:      [C]: in function 'luzer_impl.Fuzz'
7:      ...burii/reviews/ligurio-luzer/ligurio-luzer/luzer/init.lua:48: in function 'luzer.Fuzz'
7:      ...-luzer/ligurio-luzer/examples/example_custom_mutator.lua:29: in main chunk
7:      [C]: in ?
1/1 Test #7: luzer_custom_mutator_example .....***Failed  Required regular expression not found. Regex=[example_custom_mutator.lua:19: assert has triggered

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions