Skip to content

Commit 498370d

Browse files
krajotavio
authored andcommitted
chromium: Fix build with libc++ runtime on musl and update patches
libc++ does not like the conversions to long for one parameter only therefore cast both to unsigned so it matches the LHS too Fix mallinfo remains Extend res_ninit fix to new files Provide __close on musl Signed-off-by: Khem Raj <[email protected]>
1 parent eefe4f7 commit 498370d

File tree

5 files changed

+115
-1
lines changed

5 files changed

+115
-1
lines changed

meta-chromium/recipes-browser/chromium/chromium-gn.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ SRC_URI:append:libc-musl = "\
4949
file://musl/0019-adjust-thread-stack-sizes.patch \
5050
file://musl/0020-Fix-tab-crashes-on-musl.patch \
5151
file://musl/0021-pthread_getname_np.patch \
52+
file://musl/scoped-file.patch \
5253
"
5354

5455
ANY_OF_DISTRO_FEATURES = "opengl vulkan"

meta-chromium/recipes-browser/chromium/files/0001-exception_handler.cc-Match-the-types-for-SIGSTKSZ.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Signed-off-by: Khem Raj <[email protected]>
2323
// the alternative stack. Ensure that the size of the alternative stack is
2424
// large enough.
2525
- static const unsigned kSigStackSize = std::max(16384, SIGSTKSZ);
26-
+ static const unsigned kSigStackSize = std::max(static_cast<long>(16384), SIGSTKSZ);
26+
+ static const unsigned kSigStackSize = std::max(static_cast<unsigned>(16384), static_cast<unsigned>(SIGSTKSZ));
2727

2828
// Only set an alternative stack if there isn't already one, or if the current
2929
// one is too small.

meta-chromium/recipes-browser/chromium/files/musl/0001-mallinfo-implementation-is-glibc-specific.patch

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ Signed-off-by: Khem Raj <[email protected]>
2323
namespace {
2424

2525
size_t GetMallocUsageMallinfo() {
26+
@@ -134,7 +134,7 @@ size_t ProcessMetrics::GetMallocUsage()
27+
malloc_statistics_t stats = {0};
28+
malloc_zone_statistics(nullptr, &stats);
29+
return stats.size_in_use;
30+
-#elif defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
31+
+#elif defined(__GLIBC__) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
32+
return GetMallocUsageMallinfo();
33+
#elif defined(OS_FUCHSIA)
34+
// TODO(fuchsia): Not currently exposed. https://crbug.com/735087.
2635
--- a/base/trace_event/malloc_dump_provider.cc
2736
+++ b/base/trace_event/malloc_dump_provider.cc
2837
@@ -203,7 +203,7 @@ bool MallocDumpProvider::OnMemoryDump(co
@@ -67,3 +76,32 @@ Signed-off-by: Khem Raj <[email protected]>
6776

6877
/* Define to 1 if you have the <malloc/malloc.h> header file. */
6978
/* #undef HAVE_MALLOC_MALLOC_H */
79+
--- a/third_party/tflite/src/tensorflow/lite/profiling/memory_info.cc
80+
+++ b/third_party/tflite/src/tensorflow/lite/profiling/memory_info.cc
81+
@@ -14,7 +14,7 @@ limitations under the License.
82+
==============================================================================*/
83+
#include "tensorflow/lite/profiling/memory_info.h"
84+
85+
-#ifdef __linux__
86+
+#ifdef __GLIBC__
87+
#include <malloc.h>
88+
#include <sys/resource.h>
89+
#include <sys/time.h>
90+
@@ -27,7 +27,7 @@ namespace memory {
91+
const int MemoryUsage::kValueNotSet = 0;
92+
93+
bool MemoryUsage::IsSupported() {
94+
-#ifdef __linux__
95+
+#ifdef __GLIBC__
96+
return true;
97+
#endif
98+
return false;
99+
@@ -35,7 +35,7 @@ bool MemoryUsage::IsSupported() {
100+
101+
MemoryUsage GetMemoryUsage() {
102+
MemoryUsage result;
103+
-#ifdef __linux__
104+
+#ifdef __GLIBC__
105+
rusage res;
106+
if (getrusage(RUSAGE_SELF, &res) == 0) {
107+
result.max_rss_kb = res.ru_maxrss;

meta-chromium/recipes-browser/chromium/files/musl/0009-provide-res_ninit-and-nclose-APIs-on-non-glibc-linux.patch

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,42 @@ Signed-off-by: Khem Raj <[email protected]>
9191
namespace net {
9292

9393
namespace {
94+
--- a/net/dns/dns_config_service_linux.cc
95+
+++ b/net/dns/dns_config_service_linux.cc
96+
@@ -35,6 +35,36 @@
97+
#include "net/dns/serial_worker.h"
98+
#include "third_party/abseil-cpp/absl/types/optional.h"
99+
100+
+#if !defined(__GLIBC__)
101+
+/***************************************************************************
102+
+ * resolv_compat.h
103+
+ *
104+
+ * Mimick GLIBC's res_ninit() and res_nclose() for musl libc
105+
+ * Note: res_init() is actually deprecated according to
106+
+ * http://docs.oracle.com/cd/E36784_01/html/E36875/res-nclose-3resolv.html
107+
+ **************************************************************************/
108+
+#include <string.h>
109+
+
110+
+static inline int res_ninit(res_state statp)
111+
+{
112+
+ int rc = res_init();
113+
+ if (statp != &_res) {
114+
+ memcpy(statp, &_res, sizeof(*statp));
115+
+ }
116+
+ return rc;
117+
+}
118+
+
119+
+static inline int res_nclose(res_state statp)
120+
+{
121+
+ if (!statp)
122+
+ return -1;
123+
+ if (statp != &_res) {
124+
+ memset(statp, 0, sizeof(*statp));
125+
+ }
126+
+ return 0;
127+
+}
128+
+#endif
129+
+
130+
namespace net {
131+
132+
namespace internal {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
provide __close on musl
2+
3+
Upstream-Status: Pending
4+
Signed-off-by: Khem Raj <[email protected]>
5+
6+
--- a/base/files/scoped_file_linux.cc
7+
+++ b/base/files/scoped_file_linux.cc
8+
@@ -7,6 +7,7 @@
9+
#include <algorithm>
10+
#include <array>
11+
#include <atomic>
12+
+#include <dlfcn.h>
13+
14+
#include "base/compiler_specific.h"
15+
#include "base/debug/stack_trace.h"
16+
@@ -80,9 +81,18 @@ bool IsFDOwned(int fd) {
17+
18+
extern "C" {
19+
20+
-int __close(int);
21+
-
22+
__attribute__((visibility("default"), noinline)) int close(int fd) {
23+
+ static int (*__close)(int) = nullptr;
24+
+
25+
+ if (__close == nullptr) {
26+
+ __close = (int (*)(int))dlsym(RTLD_NEXT, "close");
27+
+
28+
+ if (__close == nullptr) {
29+
+ RAW_LOG(ERROR, "musl close not found\n");
30+
+ IMMEDIATE_CRASH();
31+
+ }
32+
+ }
33+
+
34+
if (base::IsFDOwned(fd) && g_is_ownership_enforced)
35+
CrashOnFdOwnershipViolation();
36+
return __close(fd);

0 commit comments

Comments
 (0)