Skip to content

wasm-mutator-fuzz: make compilers overridable#3578

Merged
wenyongh merged 1 commit intobytecodealliance:mainfrom
yamt:fuzz-clang
Jul 1, 2024
Merged

wasm-mutator-fuzz: make compilers overridable#3578
wenyongh merged 1 commit intobytecodealliance:mainfrom
yamt:fuzz-clang

Conversation

@yamt
Copy link
Contributor

@yamt yamt commented Jul 1, 2024

eg.

cmake .. \
-DCMAKE_C_COMPILER=/usr/local/opt/llvm@15/bin/clang \
-DCMAKE_CXX_COMPILER=/usr/local/opt/llvm@15/bin/clang++

eg.
```shell
cmake .. \
-DCMAKE_C_COMPILER=/usr/local/opt/llvm@15/bin/clang \
-DCMAKE_CXX_COMPILER=/usr/local/opt/llvm@15/bin/clang++
```
Copy link
Contributor

@lum1n0us lum1n0us left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wenyongh wenyongh merged commit ea582fb into bytecodealliance:main Jul 1, 2024
@lum1n0us
Copy link
Contributor

lum1n0us commented Jul 1, 2024

✋ there will be a problem if both CC and CXX have been set to gcc and g++ which usually happens in linux because use GCC as the default compiler and CMAKE_<LANG>_COMPILER always point to CC and CXX.

After the PR, it requires

  • Either use clang/clang++ as the default compiler by setting CC and CXX.
  • Or always switch to clang manually, like CC=$(which clang) CXX=$(which clang++) cmake -S . -B build

Anyway, the previous, simplest command cmake -S . -B build && cmake --build build may lead to

cc: error: unrecognized argument to ‘-fsanitize=’ option: ‘fuzzer’
cc: error: unrecognized argument to ‘-fsanitize=’ option: ‘unsigned-integer-overflow’; did you mean ‘signed-integer-overflow’?
cc: error: unrecognized argument to ‘-fsanitize=’ option: ‘local-bounds’
cc: error: unrecognized argument to ‘-fsanitize=’ option: ‘nullability’
cc: error: unrecognized command-line option ‘-fprofile-instr-generate’; did you mean ‘-fprofile-generate’?
cc: error: unrecognized command-line option ‘-fcoverage-mapping’

@yamt
Copy link
Contributor Author

yamt commented Jul 1, 2024

✋ there will be a problem if both CC and CXX have been set to gcc and g++ which usually happens in linux because use GCC as the default compiler and CMAKE_<LANG>_COMPILER always point to CC and CXX.

do you mean environment variables CC and CXX are set system-wide by default?
are you sure it "usually happens in linux"?
i don't remember such distributions.

@lum1n0us
Copy link
Contributor

lum1n0us commented Jul 1, 2024

Maybe "usually" is a strong word(depends on how to setup the machine. Personal habits). But I found two available machines around me sharing the same problem because using the GCC as default compiler and ENV(CC) points to /usr/bin/cc points to gcc

@yamt
Copy link
Contributor Author

yamt commented Jul 1, 2024

if a user sets CC explicitly and it broke things, i feel it's his problem.
besides that, even clang doesn't always come with libfuzzer.
i suspect there is no magic which works on every environment.
maybe the best thing we can do here is to document the requirement.

@lum1n0us
Copy link
Contributor

lum1n0us commented Jul 1, 2024

I am thinking about following the original intention, forcing Clang compiler. It may like:

# STREQUAL or MATCH 
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  set(CMAKE_CXX_COMPILER "clang")
endif ()

@yamt
Copy link
Contributor Author

yamt commented Jul 1, 2024

I am thinking about following the original intention, forcing Clang compiler. It may like:

# STREQUAL or MATCH 
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  set(CMAKE_CXX_COMPILER "clang")
endif ()

it doesn't work if your clang doesn't ship with libfuzzer.
unfortunately it isn't too uncommon.

@lum1n0us
Copy link
Contributor

lum1n0us commented Jul 1, 2024

The problem is if not defined values(of CMAKE_C_COMPILER and CMAKE_CXX_COMPILER) in command line options, if (NOT DEFINED) ... set ... will not work. It will use values of ENV(CC) and ENV(C++).

It means the modification actually won't be executed. It's not make options overridable. It requires users always give compiler info explicitly.

@yamt
Copy link
Contributor Author

yamt commented Jul 1, 2024

The problem is if not defined values(of CMAKE_C_COMPILER and CMAKE_CXX_COMPILER) in command line options, if (NOT DEFINED) ... set ... will not work. It will use values of ENV(CC) and ENV(C++).

It means the modification actually won't be executed. It's not make options overridable. It requires users always give compiler info explicitly.

i feel we are talking past each other.

if a user specified a compiler explicitly (either via CMAKE_C_COMPILER or CC) it should be used.
if a user didn't specify a compiler explicitly, "clang" is used.

@lum1n0us
Copy link
Contributor

lum1n0us commented Jul 1, 2024

if a user didn't specify a compiler explicitly, "clang" is used.

It won't. if (NOT DEFINED CMAKE_C_COMPILER) seems always return FALSE. CMake will detect compilers at the very beginning of.

@yamt
Copy link
Contributor Author

yamt commented Jul 1, 2024

if a user didn't specify a compiler explicitly, "clang" is used.

It won't. if (NOT DEFINED CMAKE_C_COMPILER) seems always return FALSE. CMake will detect compilers at the very beginning of.

good point.
my suggested fix: #3585

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

Successfully merging this pull request may close these issues.

3 participants