[PATCH] D83494: [libFuzzer] Link libFuzzer's own interceptors when other compiler runtimes are not linked.

Dokyung Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 14 10:38:25 PDT 2020


dokyungs added a comment.

In D83494#2150643 <https://reviews.llvm.org/D83494#2150643>, @morehouse wrote:

> In D83494#2148868 <https://reviews.llvm.org/D83494#2148868>, @dokyungs wrote:
>
> > Addressed Matt's comments.
> >
> > A major change in this round that needs explanation is introduction of FuzzerPlatform.h. Previously I defined `strstr` and `strcasestr` with `extern "C++"` to workaround conflicting definition errors resulting from including <string.h>. But since including it is not necessary when compiling this interceptor module, this patch now separates out platform related macros from FuzzerDef.h into FuzzerPlatform.h, and the module includes FuzzerPlatform.h, not FuzzerDef.h.
>
>
> What was the conflicting definition error?  Does string.h have inline definitions for those functions?


I was misled; the error is actually ambiguating new "declarations", not definitions. The exact error message goes like:

  error: ambiguating new declaration of ‘char* strcasestr(const char*, const char*)’
    104 | ATTRIBUTE_INTERFACE char *strcasestr(const char *s1, const char *s2) {
        |                           ^~~~~~~~~~
  In file included from include/c++/v1/string.h:60,
                   from include/c++/v1/cstring:60,
                   from include/c++/v1/algorithm:641,
                   from include/c++/v1/__string:57,
                   from include/c++/v1/string_view:175,
                   from include/c++/v1/string:506,
                   from FuzzerInterceptors.cpp:14:
  /usr/include/string.h:356:26: note: old declaration ‘const char* strcasestr(const char*, const char*)’
    356 | extern "C++" const char *strcasestr (const char *__haystack,
        |                          ^~~~~~~~~~

C++'s declarations of strstr/strcasestr each have two different versions (const v. non const), and neither of them matches C's strstr/strcasestr declarations. So I could either (i) make libFuzzer's declarations of strstr/strcasestr match one of C++ versions (for this reason there was "extern C++ ..."), or (ii) make them match C declarations of strstr/strcasestr and remove C++ declarations by not including string.h. I realized that (ii) is a simpler solution, so I changed the code that way.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83494/new/

https://reviews.llvm.org/D83494





More information about the cfe-commits mailing list