mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.59k stars 1.62k forks source link

Does Meson support the `fpass-plugin=<value>` args of llvm compiler? #12243

Open for-just-we opened 1 year ago

for-just-we commented 1 year ago

I compile one project glib in oss-fuzz, and add -fpass-plugin=../pass.so to CFLAGS. And when configure the project, error happen. It fail to determine the size of size_t. The part of the output of configuration is:

Checking for function "mkostemp" : YES 
Checking if "futex(2) system call" : compiles: NO 
Checking if "futex(2) system call" : compiles: NO 
Checking if "eventfd(2) system call" : links: YES 
Checking if "pidfd_open(2) system call" : links: YES 
Checking if "__uint128_t available" : compiles: NO 
Checking if "clock_gettime" : links: YES 
Checking if "dlopen() and dlsym() in system libraries" : links: NO 
Checking if "dlopen() and dlsym() in libdl" : links: YES 
Library dl found: YES
Checking if "open() option O_DIRECTORY" : compiles: NO 
Checking if "fcntl() option F_FULLFSYNC" : compiles: NO 
Checking if "C99 vsnprintf" runs: YES
Checking if "C99 snprintf" runs: YES
Checking if "Unix98 printf positional parameters" runs: YES
Checking if "nl_langinfo and CODESET" : links: YES 
Checking if "nl_langinfo (PM_STR)" : links: YES 
Checking if "nl_langinfo (_NL_CTYPE_OUTDIGITn_MB)" : links: YES 
Checking if "nl_langinfo (ALTMON_n)" : links: YES 
Checking if "nl_langinfo (_NL_ABALTMON_n)" : links: YES 
Checking if "nl_langinfo and _NL_TIME_CODESET" : links: YES 
Checking if "signed" : compiles: NO 
Header <stddef.h> has symbol "ptrdiff_t" : NO 
Checking if "sig_atomic_t" : links: YES 
Checking if "long long" : compiles: NO 
Checking if "long double" : compiles: NO 
Header <stddef.h> has symbol "wchar_t" : NO 
Header <wchar.h> has symbol "wint_t" : NO 
Checking if "uintmax_t in inttypes.h" : compiles: NO 
Checking if "uintmax_t in stdint.h" : compiles: NO 
Checking for size of "char" : 1
Checking for size of "short" : 2
Checking for size of "int" : 4
Checking for size of "void*" : 8
Checking for size of "long" : 8
Checking for size of "size_t" : 8
Checking for size of "ssize_t" : 8
Checking for alignment of "char" : 1
Checking for alignment of "short" : 2
Checking for alignment of "int" : 4
Checking for alignment of "void*" : 8
Checking for alignment of "long" : 8
Checking for alignment of "long long" : 8
Checking for alignment of "size_t" : 8
Checking for size of "wchar_t" : 4
Checking if "GCC size_t typedef is long" : compiles: NO 

meson.build:1692:2: ERROR: Problem encountered: Could not determine size of size_t.

And when I check the meson-log.txt, its message is:

Program stderr:

Checking for size of "wchar_t" : 4
Running compile:
Working directory:  /src/glib/_builddir/meson-private/tmp761kib7z
Command line:  clang /src/glib/_builddir/meson-private/tmp761kib7z/testfile.c -o /src/glib/_builddir/meson-private/tmp761kib7z/output.obj -c -O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -Wl,--start-group -fpass-plugin=/extra/libs/TraceLogPass.so -Wl,--end-group -D_FILE_OFFSET_BITS=64 -O0 -Werror=implicit-function-declaration -Werror=unknown-warning-option -Werror=unused-command-line-argument -Werror=ignored-optimization-argument -std=gnu99 -Werror 

Code:
 #include <stddef.h>
        size_t f (size_t *i) { return *i + 1; }
        int main (void) {
          unsigned long i = 0;
          f (&i);
          return 0;
        }
Compiler stdout:

Compiler stderr:
 clang-15: error: -Wl,--start-group: 'linker' input unused [-Werror,-Wunused-command-line-argument]
clang-15: error: -Wl,--end-group: 'linker' input unused [-Werror,-Wunused-command-line-argument]

Checking if "GCC size_t typedef is long" : compiles: NO 

meson.build:1692:2: ERROR: Problem encountered: Could not determine size of size_t.

In the command line clang /src/glib/_builddir/meson-private/tmp761kib7z/testfile.c -o /src/glib/_builddir/meson-private/tmp761kib7z/output.obj -c -O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -Wl,--start-group -fpass-plugin=/extra/libs/TraceLogPass.so -Wl,--end-group -D_FILE_OFFSET_BITS=64 -O0 -Werror=implicit-function-declaration -Werror=unknown-warning-option -Werror=unused-command-line-argument -Werror=ignored-optimization-argument -std=gnu99 -Werror, -fpass-plugin=/extra/libs/TraceLogPass.so should not be wrapped by -Wl,--start-group -Wl,--end-group. Why did this happen. Could I fix this?

I really need to run the TraceLogPass when compiling. And I find insert this pass into LLVM is much harder. So if meson does not currently support this compile args, could I configure the project with meson without fpass-plugin=xxx. And when configuration over, I modify the compile_commands.json file to manually insert the fpass-plugin=xxx to CFLAGS?

tristan957 commented 1 year ago

This sounds like a Meson bug. It is probably doing some naive somewhere with arguments ending in .so or something. This is just a complete guess though. If you can submit a PR, that would be great!

for-just-we commented 1 year ago

This sounds like a Meson bug. It is probably doing some naive somewhere with arguments ending in .so or something. This is just a complete guess though. If you can submit a PR, that would be great!

Well, learning the mechanism of meson takes a large part of time. But I do find a way which could bypass this error. That I can imitate wllvm which is basically a wrapper of clang command. I can build a python project and generate two scripts wclang and wclang++ which is similar to wllvm and wllvm++, wclang is equally to clang -g -fpass-plugin=xxx. And export CC=wclang and export CXX=wclang++. So I don't need to explicit add the arg -fpass-plugin to CFLAGS and can avoid this error.

This can work but can slow down the process of compiling. It may be better to add support for those compilation arguments.