commit 4b29e2284032984e4a8dfc98ca6d5778c64d86f9
parent 04f729c8bcd02791254cd15380e4969503602af6
Author: Henri Sivonen <hsivonen@hsivonen.fi>
Date: Thu, 6 Nov 2025 12:57:56 +0000
Bug 1998532 - Make ContainsMarkup link when htmlaccel is unavailable and even the most basic constant propagation is turned off. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D271544
Diffstat:
3 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp
@@ -74,7 +74,9 @@
#include "mozilla/dom/SVGUseElement.h"
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/htmlaccel/htmlaccelEnabled.h"
-#include "mozilla/htmlaccel/htmlaccelNotInline.h"
+#ifdef MOZ_MAY_HAVE_HTMLACCEL
+# include "mozilla/htmlaccel/htmlaccelNotInline.h"
+#endif
#include "nsCCUncollectableMarker.h"
#include "nsChildContentList.h"
#include "nsContentCreatorFunctions.h"
@@ -1919,6 +1921,7 @@ static bool ContainsMarkup(const nsAString& aStr) {
const char16_t* start = aStr.BeginReading();
const char16_t* end = aStr.EndReading();
+#ifdef MOZ_MAY_HAVE_HTMLACCEL
if (mozilla::htmlaccel::htmlaccelEnabled()) {
// We need to check for the empty string in order to
// dereference `start` for the '<' check. We might as well
@@ -1933,6 +1936,7 @@ static bool ContainsMarkup(const nsAString& aStr) {
return mozilla::htmlaccel::ContainsMarkup(start, end);
}
}
+#endif
while (start != end) {
char16_t c = *start;
diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp
@@ -225,7 +225,9 @@
#include "mozilla/gfx/Types.h"
#include "mozilla/glean/GleanPings.h"
#include "mozilla/htmlaccel/htmlaccelEnabled.h"
-#include "mozilla/htmlaccel/htmlaccelNotInline.h"
+#ifdef MOZ_MAY_HAVE_HTMLACCEL
+# include "mozilla/htmlaccel/htmlaccelNotInline.h"
+#endif
#include "mozilla/intl/LocaleService.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/net/UrlClassifierCommon.h"
@@ -10115,10 +10117,14 @@ class StringBuilder {
// to inline the call without triggering
// https://github.com/llvm/llvm-project/issues/160886 .
if (S::SIMD && (end - ptr >= 16)) {
+ // Need to check ifdef inside here in order to make even non-opt
+ // build consider `S::SIMD` used.
+#ifdef MOZ_MAY_HAVE_HTMLACCEL
size_t skipped =
mozilla::htmlaccel::SkipNonEscapedInAttributeValue(ptr, end);
ptr += skipped;
currentPosition += skipped;
+#endif
}
while (ptr != end) {
char16_t c = *ptr;
@@ -10194,9 +10200,13 @@ class StringBuilder {
// to inline the call without triggering
// https://github.com/llvm/llvm-project/issues/160886 .
if (S::SIMD && (end - ptr >= 16)) {
+ // Need to check ifdef inside here in order to make even non-opt
+ // build consider `S::SIMD` used.
+#ifdef MOZ_MAY_HAVE_HTMLACCEL
size_t skipped = mozilla::htmlaccel::SkipNonEscapedInTextNode(ptr, end);
ptr += skipped;
currentPosition += skipped;
+#endif
}
while (ptr != end) {
T c = *ptr;
@@ -10256,10 +10266,13 @@ static void AppendEncodedCharacters(const CharacterDataBuffer* aText,
uint32_t len = aText->GetLength();
if (aText->Is2b()) {
const char16_t* data = aText->Get2b();
+#ifdef MOZ_MAY_HAVE_HTMLACCEL
if (mozilla::htmlaccel::htmlaccelEnabled()) {
numEncodedChars =
mozilla::htmlaccel::CountEscapedInTextNode(data, data + len);
- } else {
+ } else
+#endif
+ {
for (uint32_t i = 0; i < len; ++i) {
const char16_t c = data[i];
switch (c) {
@@ -10276,10 +10289,13 @@ static void AppendEncodedCharacters(const CharacterDataBuffer* aText,
}
} else {
const char* data = aText->Get1b();
+#ifdef MOZ_MAY_HAVE_HTMLACCEL
if (mozilla::htmlaccel::htmlaccelEnabled()) {
numEncodedChars =
mozilla::htmlaccel::CountEscapedInTextNode(data, data + len);
- } else {
+ } else
+#endif
+ {
for (uint32_t i = 0; i < len; ++i) {
const unsigned char c = data[i];
switch (c) {
@@ -10321,9 +10337,12 @@ static CheckedInt<uint32_t> ExtraSpaceNeededForAttrEncoding(
const char16_t* end = aValue.EndReading();
uint32_t numEncodedChars = 0;
+#ifdef MOZ_MAY_HAVE_HTMLACCEL
if (mozilla::htmlaccel::htmlaccelEnabled()) {
numEncodedChars = mozilla::htmlaccel::CountEscapedInAttributeValue(c, end);
- } else {
+ } else
+#endif
+ {
while (c < end) {
switch (*c) {
case '"':
diff --git a/parser/htmlaccel/htmlaccelEnabled.h b/parser/htmlaccel/htmlaccelEnabled.h
@@ -12,6 +12,13 @@
namespace mozilla::htmlaccel {
+// MOZ_MAY_HAVE_HTMLACCEL gets defined iff `htmlaccelEnabled()` may return
+// `true`. The purpose is this define is to accommodate builds that don't
+// link `htmlaccelNotInline.cpp` and have even the most basic constant
+// propagation turned off so that `htmlaccelEnabled()` statically returning
+// false isn't enough to remove calls to functions whose definitions are
+// missing.
+
/// This function is appropriate to call when the SIMD path is compiled
/// with `HTML_ACCEL_FLAGS`.
///
@@ -22,8 +29,10 @@ inline bool htmlaccelEnabled() {
// GCC 12 or newer is required for __builtin_shuffle.
return false;
#elif defined(__aarch64__) && defined(__LITTLE_ENDIAN__)
+# define MOZ_MAY_HAVE_HTMLACCEL 1
return true;
#elif defined(__x86_64__)
+# define MOZ_MAY_HAVE_HTMLACCEL 1
bool ret = mozilla::supports_bmi();
if (ret) {
// As a micro optimization for the innerHTML getter, don't bother