Skip to content

Commit 72885d3

Browse files
committed
[POSIX] Remove dlopen and friends from Starboard (youtube#6488)
This PR removes the usage of dlopen, dlclose, dlsym, dladdr, and dlerror from Starboard for linux-evergreen platforms. There are a lot of issues supporting these symbols for evergreen, so we have decided to remove them. Removal of these symbols is either done through disabling the code that builds them through GN flags using `is_starboard` or is done by blocking out code that calls these symbols using `!BUILDFLAG(IS_STARBOARD)`. With this change, base::unittest ElfReaderTestWithCurrentImage.ReadElfBuildId and cdm_service_broker_unittest were disabled due to these tests using these symbols. Bug: 412456510 Bug: 420913744
1 parent 60ae913 commit 72885d3

File tree

15 files changed

+94
-24
lines changed

15 files changed

+94
-24
lines changed

base/BUILD.gn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,11 @@ component("base") {
16701670
"profiler/thread_delegate_posix.cc",
16711671
"profiler/thread_delegate_posix.h",
16721672
]
1673+
1674+
if (is_starboard) {
1675+
sources -= ["native_library_posix.cc"]
1676+
sources += ["native_library_starboard.cc"]
1677+
}
16731678
}
16741679

16751680
if (is_posix && !is_android) {

base/debug/elf_reader_unittest.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,15 @@ TEST(ElfReaderTestWithCurrentElfImage, ReadElfBuildId) {
193193
EXPECT_FALSE(IsAsciiLower(c));
194194
}
195195
}
196+
// ReadElfBuildId is disabled on Starboard configurations due to its
197+
// reliance on dladdr, which Starboard does not support.
198+
#if BUILDFLAG(IS_STARBOARD)
199+
#define MAYBE_ReadElfBuildId DISABLED_ReadElfBuildId
200+
#else
201+
#define MAYBE_ReadElfBuildId ReadElfBuildId
202+
#endif
196203

197-
TEST(ElfReaderTestWithCurrentImage, ReadElfBuildId) {
204+
TEST(ElfReaderTestWithCurrentImage, MAYBE_ReadElfBuildId) {
198205
#if BUILDFLAG(IS_ANDROID)
199206
// On Android the library loader memory maps the full so file.
200207
const char kLibraryName[] = "libbase_unittests__library";

base/files/scoped_file_linux.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ bool IsFDOwned(int fd) {
8383

8484
using LibcCloseFuncPtr = int (*)(int);
8585

86+
#if !BUILDFLAG(IS_STARBOARD)
8687
// Load the libc close symbol to forward to from the close wrapper.
8788
LibcCloseFuncPtr LoadCloseSymbol() {
8889
#if defined(THREAD_SANITIZER)
@@ -95,7 +96,6 @@ LibcCloseFuncPtr LoadCloseSymbol() {
9596
#endif
9697
}
9798

98-
#if !BUILDFLAG(IS_STARBOARD)
9999
extern "C" {
100100

101101
NO_SANITIZE("cfi-icall")

base/native_library_starboard.cc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2025 The Cobalt Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "base/native_library.h"
6+
7+
#include "base/notreached.h"
8+
#include "base/strings/strcat.h"
9+
#include "base/strings/string_util.h"
10+
11+
namespace base {
12+
13+
std::string NativeLibraryLoadError::ToString() const {
14+
return message;
15+
}
16+
17+
NativeLibrary LoadNativeLibraryWithOptions(const FilePath&,
18+
const NativeLibraryOptions&,
19+
NativeLibraryLoadError*) {
20+
NOTREACHED() << "LoadNativeLibraryWithOptions called, but Starboard "
21+
<< "does not support dlopen. This call will fail.";
22+
return nullptr;
23+
}
24+
25+
void UnloadNativeLibrary(NativeLibrary) {
26+
NOTREACHED() << "UnloadNativeLibrary was called, but Starboard "
27+
<< "does not support dlclose. This call will fail.";
28+
return;
29+
}
30+
31+
void* GetFunctionPointerFromNativeLibrary(NativeLibrary,
32+
StringPiece) {
33+
NOTREACHED() << "GetFunctionPointerFromNativeLibrary was called, "
34+
<< "but Starboard does not support dlsym. This call will fail.";
35+
return nullptr;
36+
}
37+
38+
std::string GetNativeLibraryName(StringPiece name) {
39+
DCHECK(IsStringASCII(name));
40+
return StrCat({"lib", name, ".so"});
41+
}
42+
43+
std::string GetLoadableModuleName(StringPiece name) {
44+
return GetNativeLibraryName(name);
45+
}
46+
47+
} // namespace base

content/browser/speech/tts_platform_impl.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ TtsPlatform* TtsPlatform::GetInstance() {
2424

2525
// This hack exists to ensure that Starboard does not make use of dl* symbols
2626
// for hermetic builds.
27-
if BUILDFLAG(ENABLE_COBALT_HERMETIC_HACKS) {
28-
// TODO: (b/420913744) Add/Decide how to properly support the tts platform.
27+
// TODO: (b/420913744) Add/Decide how to properly support the tts platform.
28+
#if BUILDFLAG(ENABLE_COBALT_HERMETIC_HACKS)
2929
return nullptr;
30-
}
30+
#else
3131

3232
#if BUILDFLAG(IS_CHROMEOS)
3333
// On Chrome OS, the platform TTS definition is provided by the content
@@ -37,14 +37,12 @@ if BUILDFLAG(ENABLE_COBALT_HERMETIC_HACKS) {
3737
// trying to do TTS on a platform where the content client implementation
3838
// is not provided, that's probably not intended. It's not important
3939
// if this is hit in something like a content-only unit test.
40-
//
41-
// TtsPlatformImpl relies on the library speech-dispatcher, which
42-
// Starboard does not support.
4340
NOTREACHED();
4441
return nullptr;
4542
#else
4643
return TtsPlatformImpl::GetInstance();
4744
#endif
45+
#endif
4846
}
4947

5048
void TtsPlatformImpl::LoadBuiltInTtsEngine(BrowserContext* browser_context) {}

content/utility/BUILD.gn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ source_set("utility") {
143143
deps += [ "//components/services/screen_ai:screen_ai_sandbox_hook" ]
144144
}
145145

146+
if (is_starboard) {
147+
deps -= [
148+
"//content/utility/speech:speech_recognition_sandbox_hook",
149+
"//components/services/screen_ai:screen_ai_sandbox_hook",
150+
]
151+
}
152+
146153
if (enable_accessibility_service) {
147154
deps += [ "//services/accessibility:lib" ]
148155
}

content/utility/utility_main.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ int UtilityMain(MainFunctionParams parameters) {
219219
pre_sandbox_hook = base::BindOnce(&printing::PrintBackendPreSandboxHook);
220220
break;
221221
#endif // BUILDFLAG(ENABLE_OOP_PRINTING)
222+
#if !BUILDFLAG(IS_STARBOARD)
222223
case sandbox::mojom::Sandbox::kAudio:
223224
pre_sandbox_hook = base::BindOnce(&audio::AudioPreSandboxHook);
224225
break;
@@ -231,16 +232,13 @@ int UtilityMain(MainFunctionParams parameters) {
231232
pre_sandbox_hook = base::BindOnce(&screen_ai::ScreenAIPreSandboxHook);
232233
break;
233234
#endif
234-
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_ASH)
235+
#endif // !BUILDFLAG(IS_STARBOARD)
236+
#if BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_STARBOARD) || BUILDFLAG(IS_CHROMEOS_ASH)
235237
case sandbox::mojom::Sandbox::kHardwareVideoDecoding:
236-
#if BUILDFLAG(ENABLE_COBALT_HERMETIC_HACKS)
237-
COBALT_LINKER_STUB();
238-
#else // BUILDFLAG(ENABLE_COBALT_HERMETIC_HACKS)
239238
pre_sandbox_hook =
240239
base::BindOnce(&media::HardwareVideoDecodingPreSandboxHook);
241-
#endif // BUILDFLAG(ENABLE_COBALT_HERMETIC_HACKS)
242240
break;
243-
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_ASH)
241+
#endif // BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_STARBOARD) || BUILDFLAG(IS_CHROMEOS_ASH)
244242
case sandbox::mojom::Sandbox::kHardwareVideoEncoding:
245243
pre_sandbox_hook =
246244
base::BindOnce(&media::HardwareVideoEncodingPreSandboxHook);

media/gpu/sandbox/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import("//media/gpu/args.gni")
77

88
source_set("sandbox") {
99
sources = []
10-
if (is_linux || is_chromeos_ash) {
10+
if (is_linux && !is_starboard || is_chromeos_ash) {
1111
sources += [
1212
"hardware_video_decoding_sandbox_hook_linux.cc",
1313
"hardware_video_decoding_sandbox_hook_linux.h",

media/mojo/services/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ source_set("unit_tests") {
291291
"mojo_cdm_helper_unittest.cc",
292292
]
293293

294+
if (is_starboard) {
295+
sources -= [ "cdm_service_broker_unittest.cc" ]
296+
}
297+
294298
deps += [
295299
"//media/cdm:cdm_api",
296300
"//media/cdm:cdm_paths",

services/audio/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ source_set("audio") {
9191
"//services/audio/public/mojom",
9292
]
9393

94-
if (is_linux || is_chromeos) {
94+
if (is_linux && !is_starboard || is_chromeos) {
9595
sources += [
9696
"audio_sandbox_hook_linux.cc",
9797
"audio_sandbox_hook_linux.h",

0 commit comments

Comments
 (0)