Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix re-declarations of builtin functions with clang 10 #32837

Merged
merged 1 commit into from
Mar 6, 2020

Conversation

omajid
Copy link
Member

@omajid omajid commented Feb 26, 2020

Clang commit 39aa8954a4846b317d3da2f0addfce8224b438de has moved exception handling mismatches under the -fms-compatibility flag. This breaks compilation of pal under clang 10 (and newer).

The compilation error looks like this:

In file included from .../pal/src/misc/tracepointprovider.cpp:19:
In file included from .../pal/src/include/pal/palinternal.h:620:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/stdlib.h:30:
/usr/include/stdlib.h:112:36: error: exception specification in declaration does not match previous declaration
__extension__ extern long long int atoll (const char *__nptr)
                                   ^
.../pal/inc/pal.h:4227:33: note: previous declaration is here
PALIMPORT long long int __cdecl atoll(const char *) THROW_DECL;
                                ^

The simplest fix seems to be to make clang do the same thing as gcc and define THROW_DECL as throw().

Testing via https://godbolt.org shows that even clang 3.3 compiles this successfully without additional compiler options:

    extern "C" long long atoll(char const*) throw();
    #include <stdlib.h>

An alternative fix would be to use -fms-compatibility.

More details at https://bugzilla.redhat.com/show_bug.cgi?id=1807176

@omajid omajid closed this Feb 26, 2020
@omajid omajid reopened this Feb 26, 2020
@omajid omajid changed the title WIP: Fix build with clang 10 WIP: Fix re-declations of builtin functions with clang 10 Feb 26, 2020
@omajid omajid closed this Feb 26, 2020
@omajid omajid reopened this Feb 26, 2020
@omajid omajid force-pushed the clang-10-llvm-throwdecl branch 4 times, most recently from 69abe8d to 365529b Compare March 2, 2020 16:15
@omajid omajid changed the title WIP: Fix re-declations of builtin functions with clang 10 Fix re-declations of builtin functions with clang 10 Mar 2, 2020
@omajid omajid force-pushed the clang-10-llvm-throwdecl branch from 365529b to dd5c8f0 Compare March 2, 2020 16:16
@omajid omajid marked this pull request as ready for review March 2, 2020 16:16
@omajid
Copy link
Member Author

omajid commented Mar 2, 2020

Thanks to @serge-sans-paille for tracking down the root cause!

@omajid omajid force-pushed the clang-10-llvm-throwdecl branch from dd5c8f0 to 4ead130 Compare March 2, 2020 16:56
Clang commit 39aa8954a4846b317d3da2f0addfce8224b438de has moved
exception handling mismatches under the -fms-compatibility flag. This
breaks compilation of pal under clang 10 (and newer).

The compilation error looks like this:

In file included from .../pal/src/misc/tracepointprovider.cpp:19:
In file included from .../pal/src/include/pal/palinternal.h:620:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/stdlib.h:30:
/usr/include/stdlib.h:112:36: error: exception specification in declaration does not match previous declaration
__extension__ extern long long int atoll (const char *__nptr)
                                   ^
.../pal/inc/pal.h:4227:33: note: previous declaration is here
PALIMPORT long long int __cdecl atoll(const char *) THROW_DECL;
                                ^

The simplest fix seems to be to make clang do the same thing as gcc and
define THROW_DECL as 'throw()'.

Testing via https://godbolt.org shows that even clang 3.3 compiles this
successfully without additional compiler options:

    extern "C" long long atoll(char const*) throw();
    #include <stdlib.h>

An alternative fix would be to use -fms-compatibility.

More details at https://bugzilla.redhat.com/show_bug.cgi?id=1807176
@omajid omajid force-pushed the clang-10-llvm-throwdecl branch from 4ead130 to 4c8f9b2 Compare March 2, 2020 16:59
@omajid omajid changed the title Fix re-declations of builtin functions with clang 10 Fix re-declarations of builtin functions with clang 10 Mar 2, 2020
@omajid
Copy link
Member Author

omajid commented Mar 6, 2020

cc'ing some folks who last touched this part of the code, hoping to get a review: @janvorli @franksinankaya

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@janvorli janvorli merged commit 9dd7cb5 into dotnet:master Mar 6, 2020
@omajid
Copy link
Member Author

omajid commented Mar 9, 2020

I just noticed that src/coreclr/src/pal/inc/mbusafecrt.h includes a similar declaration. Is it worth it fixing that too just for consistency?

omajid added a commit to omajid/dotnet-coreclr that referenced this pull request Mar 11, 2020
This fixes 3 different set of build issues are seen when compiling with
clang 10.

- Clang 10 fails to compile slist.h because the code contained is
  actually invalid. The assignment operator being used doesn't exist.

  This is a backport of dotnet/runtime#33096

- Clang 10 has moved exception-handling mismatches in function
  declarations under the -fms-compatibility flag (instead of the
  -fms-extensions flag). Our declarations of atoll and other similar
  functions are missing the exception declaration `throw()`. This
  mismatch in exception declarations makes clang 10 unable to build this
  code. Fix it by defining THROW_DECL as `throw()` which is supported at
  least as far back as clang 3.3.

  This is a backport of dotnet/runtime#32837

- Clang 10 has enabled (or made default?) the `misleading-indentation`
  warning which causes errors when trying to compile code in
  src/tools/metainfo/mdinfo.cpp.

  This is a backport of dotnet/runtime#33406
omajid added a commit to omajid/dotnet-coreclr that referenced this pull request Mar 16, 2020
This fixes 3 different set of build issues are seen when compiling with
clang 10.

- Clang 10 fails to compile slist.h because the code contained is
  actually invalid. The assignment operator being used doesn't exist.

  This is a backport of dotnet/runtime#33096

- Clang 10 has moved exception-handling mismatches in function
  declarations under the -fms-compatibility flag (instead of the
  -fms-extensions flag). Our declarations of atoll and other similar
  functions are missing the exception declaration `throw()`. This
  mismatch in exception declarations makes clang 10 unable to build this
  code. Fix it by defining THROW_DECL as `throw()` which is supported at
  least as far back as clang 3.3.

  This is a backport of dotnet/runtime#32837

- Clang 10 has enabled additional warnings. Lets turn of -Werror
  globally in this release branch by making the `-ignorewarnings` switch
  to `./build.sh` be the default.
omajid added a commit to omajid/dotnet-coreclr that referenced this pull request Mar 16, 2020
This fixes 3 different sets of build issues seen when compiling with
Clang 10.

- Clang 10 fails to compile slist.h because the code contained is
  actually invalid. The assignment operator being used doesn't exist.

  This is a backport of dotnet/runtime#33096

- Clang 10 has moved exception-handling mismatches in function
  declarations under the -fms-compatibility flag (instead of the
  -fms-extensions flag). Our declarations of atoll and other similar
  functions are missing the exception declaration `throw()`. This
  mismatch in exception declarations makes clang 10 unable to build this
  code. Fix it by defining THROW_DECL as `throw()` which is supported at
  least as far back as clang 3.3.

  This is a backport of dotnet/runtime#32837

- Clang 10 has enabled additional warnings. Lets turn of -Werror
  globally in this release branch by making the `-ignorewarnings` switch
  to `./build.sh` be the default.
Anipik pushed a commit to dotnet/coreclr that referenced this pull request Mar 25, 2020
This fixes 3 different sets of build issues seen when compiling with
Clang 10.

- Clang 10 fails to compile slist.h because the code contained is
  actually invalid. The assignment operator being used doesn't exist.

  This is a backport of dotnet/runtime#33096

- Clang 10 has moved exception-handling mismatches in function
  declarations under the -fms-compatibility flag (instead of the
  -fms-extensions flag). Our declarations of atoll and other similar
  functions are missing the exception declaration `throw()`. This
  mismatch in exception declarations makes clang 10 unable to build this
  code. Fix it by defining THROW_DECL as `throw()` which is supported at
  least as far back as clang 3.3.

  This is a backport of dotnet/runtime#32837

- Clang 10 has enabled additional warnings. Lets turn of -Werror
  globally in this release branch by making the `-ignorewarnings` switch
  to `./build.sh` be the default.
omajid added a commit to omajid/dotnet-coreclr that referenced this pull request Jun 2, 2020
This contains a grab bag of fixes to fix the build with clang 10.

- dotnet#23075

  Fix missing includes in coreclr/src/debug/createdump/

- dotnet/runtime#33096

  SList::Init: add missing constructor

- A subset of dotnet#22129

  Just the parts that introduce the THROW_DECL macro in pal.h

- dotnet/runtime#32837

  This fixes THROW_DECL introduce in the previous PR to work with clang, which
  is required in clang 10.

- One new change:

  In a significant divergance, this commits adds more THROW_DECL macros
  to all the math functions to address a ton of errors pointed out when
  building SOS:

    In file included from /home/omajid/devel/dotnet/coreclr/src/ToolBox/SOS/Strike/strike.cpp:116:
    In file included from /home/omajid/devel/dotnet/coreclr/src/vm/hillclimbing.h:19:
    In file included from /home/omajid/devel/dotnet/coreclr/src/inc/complex.h:16:
    In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/math.h:36:
    In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/cmath:45:
    In file included from /usr/include/math.h:290:
    /usr/include/bits/mathcalls.h:53:13: error: exception specification in declaration does not match previous declaration
    __MATHCALL (acos,, (_Mdouble_ __x));
                ^
    /home/omajid/devel/dotnet/coreclr/src/pal/inc/pal.h:4395:26: note: previous declaration is here
    PALIMPORT double __cdecl acos(double);
                             ^

  Then, to make sure the declarations and implementations match, it adds
  THROW_DECL to the definitions in src/pal/src/cruntime/math.cpp
omajid added a commit to omajid/dotnet-coreclr that referenced this pull request Jun 2, 2020
This contains a grab bag of fixes to fix the build with clang 10.

- dotnet#23075

  Fix missing includes in coreclr/src/debug/createdump/

- dotnet/runtime#33096

  SList::Init: add missing constructor

- A subset of dotnet#22129

  Just the parts that introduce the THROW_DECL macro in pal.h

- dotnet/runtime#32837

  This fixes THROW_DECL introduce in the previous PR to work with clang, which
  is required in clang 10.

- One new change:

  In a significant divergance, this commits adds more THROW_DECL macros
  to all the math functions to address a ton of errors pointed out when
  building SOS:

    In file included from /home/omajid/devel/dotnet/coreclr/src/ToolBox/SOS/Strike/strike.cpp:116:
    In file included from /home/omajid/devel/dotnet/coreclr/src/vm/hillclimbing.h:19:
    In file included from /home/omajid/devel/dotnet/coreclr/src/inc/complex.h:16:
    In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/math.h:36:
    In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/cmath:45:
    In file included from /usr/include/math.h:290:
    /usr/include/bits/mathcalls.h:53:13: error: exception specification in declaration does not match previous declaration
    __MATHCALL (acos,, (_Mdouble_ __x));
                ^
    /home/omajid/devel/dotnet/coreclr/src/pal/inc/pal.h:4395:26: note: previous declaration is here
    PALIMPORT double __cdecl acos(double);
                             ^

  Then, to make sure the declarations and implementations match, it adds
  THROW_DECL to the definitions in src/pal/src/cruntime/math.cpp

Co-authored-by: Mike McLaughlin <mikem@microsoft.com>
Co-authored-by: Sinan Kaya <sinan.kaya@microsoft.com>
Co-authored-by: Tom Deseyn <tom.deseyn@gmail.com>
Anipik pushed a commit to dotnet/coreclr that referenced this pull request Jun 11, 2020
This contains a grab bag of fixes to fix the build with clang 10.

- #23075

  Fix missing includes in coreclr/src/debug/createdump/

- dotnet/runtime#33096

  SList::Init: add missing constructor

- A subset of #22129

  Just the parts that introduce the THROW_DECL macro in pal.h

- dotnet/runtime#32837

  This fixes THROW_DECL introduce in the previous PR to work with clang, which
  is required in clang 10.

- One new change:

  In a significant divergance, this commits adds more THROW_DECL macros
  to all the math functions to address a ton of errors pointed out when
  building SOS:

    In file included from /home/omajid/devel/dotnet/coreclr/src/ToolBox/SOS/Strike/strike.cpp:116:
    In file included from /home/omajid/devel/dotnet/coreclr/src/vm/hillclimbing.h:19:
    In file included from /home/omajid/devel/dotnet/coreclr/src/inc/complex.h:16:
    In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/math.h:36:
    In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/cmath:45:
    In file included from /usr/include/math.h:290:
    /usr/include/bits/mathcalls.h:53:13: error: exception specification in declaration does not match previous declaration
    __MATHCALL (acos,, (_Mdouble_ __x));
                ^
    /home/omajid/devel/dotnet/coreclr/src/pal/inc/pal.h:4395:26: note: previous declaration is here
    PALIMPORT double __cdecl acos(double);
                             ^

  Then, to make sure the declarations and implementations match, it adds
  THROW_DECL to the definitions in src/pal/src/cruntime/math.cpp

Co-authored-by: Mike McLaughlin <mikem@microsoft.com>
Co-authored-by: Sinan Kaya <sinan.kaya@microsoft.com>
Co-authored-by: Tom Deseyn <tom.deseyn@gmail.com>

Co-authored-by: Mike McLaughlin <mikem@microsoft.com>
Co-authored-by: Sinan Kaya <sinan.kaya@microsoft.com>
Co-authored-by: Tom Deseyn <tom.deseyn@gmail.com>
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants