__EXCEPTIONS and mac

209 views
Skip to first unread message

Scott Violet

unread,
Aug 9, 2024, 10:39:28 AM8/9/24
to Nico Weber, bu...@chromium.org, Clark Duvall, Sophie Chang
Hello,

One of the third_party libraries we pull in is eigen. This library conditionally enables exceptions. One of the ifdefs it looks for to determine if it should enable exceptions is __EXCEPTIONS. It seems that this define is set on mac and none of the other platforms. I verified --fno-exceptions is on the command line of the file that triggers the exceptions. Does this seem right?



Thanks,

   -Scott

Nico Weber

unread,
Aug 9, 2024, 10:57:35 AM8/9/24
to Scott Violet, Nico Weber, bu...@chromium.org, Clark Duvall, Sophie Chang
I think __EXCEPTIONS is getting set on macOS when compiling Objective-C(++) files (.m, .mm), but not when building C++ files:

```
 % ~/src/chrome/src/third_party/llvm-build/Release+Asserts/bin/clang -c -x objective-c++ /dev/null -E -dM -fno-exceptions | grep EXCEPT
#define OBJC_ZEROCOST_EXCEPTIONS 1
#define __EXCEPTIONS 1

 % ~/src/chrome/src/third_party/llvm-build/Release+Asserts/bin/clang -c -x c++ /dev/null -E -dM -fno-exceptions | grep EXCEPT
# nothing
```

(`-x` tells clang the file type of the input file. I'm using `/dev/null` as input, so clang can't get the file type from the input file's extension like it usually does. Instead of `-x c++ /dev/null`, `touch empty.cc` and passing that would work the same.)

This is because -fno-exceptions disables C++ exceptions but not Objective-C exceptions.

If you disable Objective-C exceptions as well, it stops being defined:

```
% ~/src/chrome/src/third_party/llvm-build/Release+Asserts/bin/clang -c -x objective-c++ /dev/null -E -dM -fno-exceptions -fno-objc-exceptions | grep EXCEPT
```

In general, system libraries can throw (objc) exceptions, and user code sometimes has to catch them, so we don't disable ObjC exceptions globally.

Possible options:

* Move the code this is about from a .mm to a .cc file
* Ask upstream to use `__cpp_exceptions` instead of `__EXCEPTIONS`, which cleanly maps to just the C++ -fexceptions toggle and is unaffected by ObjC exception state
* Check if that code can be built with -fno-objc-exceptions

I think this is all working as intended from the toolchain side. (I agree it's confusing, and it took me a few minutes to figure it out.)

--
You received this message because you are subscribed to the Google Groups "build" group.
To unsubscribe from this group and stop receiving emails from it, send an email to build+un...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/build/CAKARY_%3DWCOJVe%2BfTh%2Bz22Z1tLPDrGVDYfTxrc-wAtNqjn9VN2A%40mail.gmail.com.

Mark Mentovai

unread,
Aug 9, 2024, 11:02:55 AM8/9/24
to Nico Weber, Scott Violet, Nico Weber, bu...@chromium.org, Clark Duvall, Sophie Chang
But this is failing while building matrix.cc, which is definitely not an .mm file.

(Curses are directed at autoninja/siso/reclient for not showing the compiler invocation when something fails.)

Nico Weber

unread,
Aug 9, 2024, 11:04:51 AM8/9/24
to Mark Mentovai, Scott Violet, Nico Weber, bu...@chromium.org, Clark Duvall, Sophie Chang

The build is passing -ObjC++ for that file, which turns it into an ObjC++ file.

(See raw_io.output_text; siso sadly hides the compile line quite a bit 😞)

Mark Mentovai

unread,
Aug 9, 2024, 11:15:18 AM8/9/24
to Nico Weber, Scott Violet, Nico Weber, bu...@chromium.org, Clark Duvall, Sophie Chang
Oh, I was looking for -x objective-c++. Yes, we should stop building C++ as Objective-C++.

mark@arm-and-hammer zsh% git grep -F -- -ObjC++ '**/*.gn' '**/*.gni'
third_party/mediapipe/BUILD.gn:    cflags = [ "-ObjC++" ]


That’s here, and it was presumably done because resource_util_apple.cc is actually Objective-C++ source.

That file should be renamed to have a proper .mm extension, rather than polluting all of the other files that share its target with Objective-C semantics.

Scott Violet

unread,
Aug 9, 2024, 11:16:47 AM8/9/24
to Mark Mentovai, Nico Weber, Nico Weber, bu...@chromium.org, Clark Duvall, Sophie Chang
Yes, I came across this when messaging with Nico. I'm going to see about putting the file that needs -ObjC++ into isn't target.

  -Scott

Dirk Pranke

unread,
Aug 9, 2024, 3:09:14 PM8/9/24
to Nico Weber, Mark Mentovai, Scott Violet, Nico Weber, bu...@chromium.org, Clark Duvall, Sophie Chang
On Fri, Aug 9, 2024 at 8:04 AM Nico Weber <tha...@chromium.org> wrote:

The build is passing -ObjC++ for that file, which turns it into an ObjC++ file.

(See raw_io.output_text; siso sadly hides the compile line quite a bit 😞)

Have we filed a bug w/ the Siso folks to get them to fix this?

-- Dirk

Nico Weber

unread,
Aug 9, 2024, 3:45:36 PM8/9/24
to Dirk Pranke, Mark Mentovai, Scott Violet, Nico Weber, build, Clark Duvall, Sophie Chang

I filed b/333693728 a while ago.

Reply all
Reply to author
Forward
0 new messages