Skip to content

Commit

Permalink
Include -fsanitize flags with OTHER_TAPI_FLAGS during builds
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=260119
<rdar://113800841>

Reviewed by Alex Christensen.

Although there are currently no build failures with TAPI and a Sanitizer
enabled, this is a correctness fix to prevent such issues by passing the
proper -fsanitize flags during the InstallAPI (TAPI) build phase.

* Configurations/CommonBase.xcconfig:
(WK_COMMON_OTHER_TAPI_FLAGS): Add.
- Extract common flags from OTHER_TAPI_FLAGS in project xcconfig files.
- Add $(WK_SANITIZER_OTHER_TAPI_FLAGS) from Sanitizers.xcconfig.
(OTHER_TAPI_FLAGS):
- Add $(WK_COMMON_OTHER_TAPI_FLAGS) in OTHER_TAPI_FLAGS.

* Configurations/Sanitizers.xcconfig:
(WK_SANITIZER_OTHER_TAPI_FLAGS): Add.
- Includes variables below based on whether various sanitizers are
  enabled during the build.
(WK_SANITIZER_OTHER_TAPI_FLAGS_ASAN_YES): Add.
(WK_SANITIZER_OTHER_TAPI_FLAGS_LIBFUZZER_YES): Add.
(WK_SANITIZER_OTHER_TAPI_FLAGS_TSAN_YES): Add.
(WK_SANITIZER_OTHER_TAPI_FLAGS_UBSAN_YES): Add.
- Sanitizer-specific flags for use with OTHER_TAPI_FLAGS.

* Source/JavaScriptCore/Configurations/JavaScriptCore.xcconfig:
(OTHER_TAPI_FLAGS):
* Source/WebKit/Configurations/Base.xcconfig:
(OTHER_TAPI_FLAGS):
* Source/WebKitLegacy/mac/Configurations/WebKitLegacy.xcconfig:
(OTHER_TAPI_FLAGS):
- Add $(inherited) to OTHER_TAPI_FLAGS so that the definition in
  Configurations/CommonBase.xcconfig is included.

Canonical link: https://commits.webkit.org/266867@main
  • Loading branch information
David Kilzer authored and ddkilzer committed Aug 14, 2023
1 parent a2b2983 commit 79c9704
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Configurations/CommonBase.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ OTHER_CPLUSPLUSFLAGS = $(inherited) $(WK_COMMON_OTHER_CPLUSPLUSFLAGS);
WK_COMMON_OTHER_LDFLAGS = $(WK_SANITIZER_OTHER_LDFLAGS);
OTHER_LDFLAGS = $(inherited) $(WK_COMMON_OTHER_LDFLAGS);

WK_COMMON_OTHER_TAPI_FLAGS = -x objective-c++ -std=c++2a -fno-rtti $(WK_SANITIZER_OTHER_TAPI_FLAGS);
OTHER_TAPI_FLAGS = $(inherited) $(WK_COMMON_OTHER_TAPI_FLAGS);

WK_COMMON_WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wextra -Wformat=2 -Wundef;
WARNING_CFLAGS = $(inherited) $(WK_COMMON_WARNING_CFLAGS);

Expand Down
6 changes: 6 additions & 0 deletions Configurations/Sanitizers.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ WK_SANITIZER_OTHER_CPLUSPLUSFLAGS = $(WK_ADDRESS_SANITIZER_OTHER_CPLUSPLUSFLAGS_

WK_SANITIZER_OTHER_LDFLAGS = $(WK_ANY_SANITIZER_LDFLAGS_$(WK_ANY_SANITIZER_ENABLED)) $(WK_LIBFUZZER_OTHER_LDFLAGS_$(ENABLE_LIBFUZZER));

WK_SANITIZER_OTHER_TAPI_FLAGS = $(WK_SANITIZER_OTHER_TAPI_FLAGS_ASAN_$(ENABLE_ADDRESS_SANITIZER)) $(WK_SANITIZER_OTHER_TAPI_FLAGS_LIBFUZZER_$(ENABLE_LIBFUZZER)) $(WK_SANITIZER_OTHER_TAPI_FLAGS_TSAN_$(ENABLE_THREAD_SANITIZER)) $(WK_SANITIZER_OTHER_TAPI_FLAGS_UBSAN_$(ENABLE_UNDEFINED_BEHAVIOR_SANITIZER));
WK_SANITIZER_OTHER_TAPI_FLAGS_ASAN_YES = -Xparser -fsanitize=address;
WK_SANITIZER_OTHER_TAPI_FLAGS_LIBFUZZER_YES = -Xparser -fsanitize=fuzzer;
WK_SANITIZER_OTHER_TAPI_FLAGS_TSAN_YES = -Xparser -fsanitize=thread;
WK_SANITIZER_OTHER_TAPI_FLAGS_UBSAN_YES = -Xparser -fsanitize=undefined;

// All Sanitizers

// FIXME: Tell Xcode not to compile host-side tools with sanitizers enabled (see <rdar://99386433>).
Expand Down
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/Configurations/JavaScriptCore.xcconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2009-2022 Apple Inc. All rights reserved.
// Copyright (C) 2009-2023 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -47,7 +47,7 @@ TAPI_USE_SRCROOT_XCODE_SINCE_15 = YES;
TAPI_ENABLE_PROJECT_HEADERS = YES;
TAPI_VERIFY_MODE = Pedantic;
// C++ dialect flags (-std, -fvisibility, -fno-rtti) are needed because JavaScriptCore / WTF private headers are only safe to use from other WebKit projects, which build with the same dialect.
OTHER_TAPI_FLAGS = -x objective-c++ -std=c++2a -fno-rtti -fvisibility=hidden -exclude-private-header **/*SPI.h -extra-project-header $(SRCROOT)/API/ExtraSymbolsForTAPI.h $(OTHER_TAPI_FLAGS_STATICLIBS_$(DEPLOYMENT_LOCATION));
OTHER_TAPI_FLAGS = $(inherited) -fvisibility=hidden -exclude-private-header **/*SPI.h -extra-project-header $(SRCROOT)/API/ExtraSymbolsForTAPI.h $(OTHER_TAPI_FLAGS_STATICLIBS_$(DEPLOYMENT_LOCATION));
// JavaScriptCore exports libWTF.a and libbmalloc.a, so tapi needs to know about headers from those projects. The extra filelists are generated by their respective projects. In install-style builds, there is a postprocessing step done as a JavaScriptCore build phase.
OTHER_TAPI_FLAGS_STATICLIBS_NO = -filelist $(BUILT_PRODUCTS_DIR)/usr/local/include/bmalloc/bmalloc.json -filelist $(BUILT_PRODUCTS_DIR)/usr/local/include/wtf/WTF.json
OTHER_TAPI_FLAGS_STATICLIBS_YES = -filelist $(DERIVED_FILE_DIR)/bmalloc.json -filelist $(DERIVED_FILE_DIR)/WTF.json
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/Configurations/Base.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ OTHER_CPLUSPLUSFLAGS = $(inherited) -isystem $(SDKROOT)/System/Library/Framework
SUPPORTS_TEXT_BASED_API = $(TAPI_USE_SRCROOT);
SUPPORTS_TEXT_BASED_API[sdk=iphone*] = YES;

OTHER_TAPI_FLAGS = -x objective-c++ -std=c++2a -fno-rtti -DRELEASE_WITHOUT_OPTIMIZATIONS;
OTHER_TAPI_FLAGS = $(inherited) -DRELEASE_WITHOUT_OPTIMIZATIONS;
TAPI_USE_SRCROOT = $(TAPI_USE_SRCROOT$(WK_XCODE_15));
TAPI_USE_SRCROOT_XCODE_SINCE_15 = YES;
TAPI_VERIFY_MODE = Pedantic;
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKitLegacy/mac/Configurations/WebKitLegacy.xcconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2009-2022 Apple Inc. All rights reserved.
// Copyright (C) 2009-2023 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -117,7 +117,7 @@ TAPI_USE_SRCROOT_XCODE_SINCE_15 = YES;
TAPI_VERIFY_MODE = Pedantic;

// FIXME: Replace -extra-*-header and -exclude-*-header flags with build setting equivalents once rdar://99885053 is completed in all needed toolchains.
OTHER_TAPI_FLAGS = -x objective-c++ -std=c++2a -fno-rtti -fvisibility-inlines-hidden $(WK_CFLAGS_BUILD_FOR_TESTING_$(WK_BUILD_FOR_TESTING)) -DRELEASE_WITHOUT_OPTIMIZATIONS -exclude-private-header $(BUILT_PRODUCTS_DIR)/$(PRIVATE_HEADERS_FOLDER_PATH)/NSURLDownloadSPI.h -extra-private-header $(SOURCE_ROOT)/mac/TestingFunctions.h -extra-private-header $(SOURCE_ROOT)/mac/ExtraPrivateSymbolsForTAPI.h $(OTHER_TAPI_FLAGS_SRCROOT_$(TAPI_USE_SRCROOT));
OTHER_TAPI_FLAGS = $(inherited) -fvisibility-inlines-hidden $(WK_CFLAGS_BUILD_FOR_TESTING_$(WK_BUILD_FOR_TESTING)) -DRELEASE_WITHOUT_OPTIMIZATIONS -exclude-private-header $(BUILT_PRODUCTS_DIR)/$(PRIVATE_HEADERS_FOLDER_PATH)/NSURLDownloadSPI.h -extra-private-header $(SOURCE_ROOT)/mac/TestingFunctions.h -extra-private-header $(SOURCE_ROOT)/mac/ExtraPrivateSymbolsForTAPI.h $(OTHER_TAPI_FLAGS_SRCROOT_$(TAPI_USE_SRCROOT));
// Include WebKitPrefix.h to work around rdar://104248994.
OTHER_TAPI_FLAGS_SRCROOT_YES = -Xparser -include -Xparser mac/WebKitPrefix.h $(OTHER_TAPI_FLAGS_102197642_WORKAROUND);

Expand Down

0 comments on commit 79c9704

Please sign in to comment.