kenz-gelsoft / Inari

0 stars 0 forks source link

other linker issues #30

Open kenz-gelsoft opened 1 year ago

kenz-gelsoft commented 1 year ago
158:00.93 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: ../../../netwerk/dns/Unified_cpp_netwerk_dns0.o: in function `mozilla::net::NetAddr::ToStringBuffer(char*, unsigned int) const':
158:00.93 /boot/home/src/firefox-102.9.0/netwerk/dns/DNS.cpp:(.text._ZNK7mozilla3net7NetAddr14ToStringBufferEPcj+0xaf): undefined reference to `inet_ntop'
158:00.93 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: ../../../netwerk/dns/Unified_cpp_netwerk_dns0.o: in function `mozilla::net::NetAddr::ToString() const':
158:00.93 /boot/home/src/firefox-102.9.0/netwerk/dns/DNS.cpp:(.text._ZNK7mozilla3net7NetAddr8ToStringEv+0xf4): undefined reference to `inet_ntop'
158:00.93 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: ../../../netwerk/dns/Unified_cpp_netwerk_dns0.o: in function `mozilla::net::ChildDNSRecord::GetNextAddrAsString(nsTSubstring<char>&)':
158:00.93 /boot/home/src/firefox-102.9.0/netwerk/dns/DNS.cpp:(.text._ZN7mozilla3net14ChildDNSRecord19GetNextAddrAsStringER12nsTSubstringIcE+0xc3): undefined reference to `inet_ntop'
158:06.12 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: ../../../ipc/chromium/Unified_cpp_ipc_chromium1.o: in function `IPC::Channel::ChannelImpl::SetPipe(int)':
158:06.12 /boot/home/src/firefox-102.9.0/ipc/chromium/src/chrome/common/ipc_channel_posix.cc:176: undefined reference to `getsockopt'
158:06.12 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: ../../../ipc/chromium/Unified_cpp_ipc_chromium1.o: in function `IPC::Channel::CreateRawPipe(mozilla::UniquePtr<int, mozilla::detail::FileHandleDeleter>*, mozilla::UniquePtr<int, mozilla::detail::FileHandleDeleter>*)':
158:06.12 /boot/home/src/firefox-102.9.0/ipc/chromium/src/chrome/common/ipc_channel_posix.cc:1234: undefined reference to `socketpair'
158:06.12 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: ../../../ipc/chromium/Unified_cpp_ipc_chromium1.o: in function `IPC::(anonymous namespace)::corrected_sendmsg(int, msghdr const*, int)':
158:06.12 /boot/home/src/firefox-102.9.0/ipc/chromium/src/chrome/common/ipc_channel_posix.cc:134: undefined reference to `sendmsg'
158:06.12 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: ../../../ipc/chromium/Unified_cpp_ipc_chromium1.o: in function `IPC::Channel::ChannelImpl::ProcessIncomingMessages()':
158:06.12 /boot/home/src/firefox-102.9.0/ipc/chromium/src/chrome/common/ipc_channel_posix.cc:296: undefined reference to `recvmsg'
158:06.36 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: ../../../ipc/chromium/src/third_party/Unified_c_src_third_party0.o: in function `event_base_new_with_config':
158:06.36 /boot/home/src/firefox-102.9.0/ipc/chromium/src/third_party/libevent/event.c:(.text.event_base_new_with_config+0x2c0): undefined reference to `epollops'
158:06.36 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: ../../../ipc/chromium/src/third_party/Unified_c_src_third_party0.o: relocation R_X86_64_PC32 against undefined hidden symbol `epollops' can not be used when making a shared object
158:06.43 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: final link failed: bad value
158:06.79 collect2: error: ld returned 1 exit status
158:06.80 clang-12: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
kenz-gelsoft commented 1 year ago

for inet_ntop

diff --git a/ipc/chromium/src/third_party/libevent/evutil.c b/ipc/chromium/src/third_party/libevent/evutil.c
index 9817f08643..50c7b997be 100644
--- a/ipc/chromium/src/third_party/libevent/evutil.c
+++ b/ipc/chromium/src/third_party/libevent/evutil.c
@@ -1895,7 +1895,7 @@ evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap)
 const char *
 evutil_inet_ntop(int af, const void *src, char *dst, size_t len)
 {
-#if defined(EVENT__HAVE_INET_NTOP) && !defined(USE_INTERNAL_NTOP)
+#if (defined(EVENT__HAVE_INET_NTOP) && !defined(__HAIKU__)) && !defined(USE_INTERNAL_NTOP)
        return inet_ntop(af, src, dst, len);
 #else
        if (af == AF_INET) {
@@ -2680,7 +2680,7 @@ evutil_make_internal_pipe_(evutil_socket_t fd[2])
          or woken up and in the process of draining it.
        */

-#if defined(EVENT__HAVE_PIPE2)
+#if defined(EVENT__HAVE_PIPE2) && !defined(__HAIKU__)
        if (pipe2(fd, O_NONBLOCK|O_CLOEXEC) == 0)
                return 0;
 #endif
@@ -2729,7 +2729,7 @@ evutil_make_internal_pipe_(evutil_socket_t fd[2])
 evutil_socket_t
 evutil_eventfd_(unsigned initval, int flags)
 {
-#if defined(EVENT__HAVE_EVENTFD) && defined(EVENT__HAVE_SYS_EVENTFD_H)
+#if defined(EVENT__HAVE_EVENTFD) && defined(EVENT__HAVE_SYS_EVENTFD_H) && !defined(__HAIKU__)
        int r;
 #if defined(EFD_CLOEXEC) && defined(EFD_NONBLOCK)
        r = eventfd(initval, flags);
diff --git a/ipc/chromium/src/third_party/libevent/test/regress_dns.c b/ipc/chromium/src/third_party/libevent/test/regress_dns.c
index 9a8bff4f15..60102faf1c 100644
--- a/ipc/chromium/src/third_party/libevent/test/regress_dns.c
+++ b/ipc/chromium/src/third_party/libevent/test/regress_dns.c
@@ -107,7 +107,7 @@ dns_gethostbyname_cb(int result, char type, int count, int ttl,

        switch (type) {
        case DNS_IPv6_AAAA: {
-#if defined(EVENT__HAVE_STRUCT_IN6_ADDR) && defined(EVENT__HAVE_INET_NTOP) && defined(INET6_ADDRSTRLEN)
+#if defined(EVENT__HAVE_STRUCT_IN6_ADDR) && (defined(EVENT__HAVE_INET_NTOP) && !defined(__HAIKU__)) && defined(INET6_ADDRSTRLEN)
                struct in6_addr *in6_addrs = addresses;
                char buf[INET6_ADDRSTRLEN+1];
                int i;
@@ -328,7 +328,7 @@ dns_server_gethostbyname_cb(int result, char type, int count, int ttl,
                break;
        }
        case DNS_IPv6_AAAA: {
-#if defined (EVENT__HAVE_STRUCT_IN6_ADDR) && defined(EVENT__HAVE_INET_NTOP) && defined(INET6_ADDRSTRLEN)
+#if defined (EVENT__HAVE_STRUCT_IN6_ADDR) && (defined(EVENT__HAVE_INET_NTOP) && !defined(__HAIKU__)) && defined(INET6_ADDRSTRLEN)
                struct in6_addr *in6_addrs = addresses;
                char buf[INET6_ADDRSTRLEN+1];
                if (memcmp(&in6_addrs[0].s6_addr, "abcdefghijklmnop", 16)
diff --git a/netwerk/dns/moz.build b/netwerk/dns/moz.build
index 5d81059ed8..4f237b6feb 100644
--- a/netwerk/dns/moz.build
+++ b/netwerk/dns/moz.build
@@ -109,4 +109,7 @@ LOCAL_INCLUDES += [
     "/netwerk/protocol/http",
 ]

+OS_LIBS += [
+    "network"
+]
 USE_LIBS += ["icu"]
kenz-gelsoft commented 1 year ago

for epollops

diff --git a/ipc/chromium/src/third_party/libevent/event.c b/ipc/chromium/src/third_party/libevent/event.c
index 7a42b73191..d0f22ba368 100644
--- a/ipc/chromium/src/third_party/libevent/event.c
+++ b/ipc/chromium/src/third_party/libevent/event.c
@@ -86,7 +86,7 @@ extern const struct eventop selectops;
 #ifdef EVENT__HAVE_POLL
 extern const struct eventop pollops;
 #endif
-#ifdef EVENT__HAVE_EPOLL
+#if defined(EVENT__HAVE_EPOLL) && !defined(__HAIKU__)
 extern const struct eventop epollops;
 #endif
 #ifdef EVENT__HAVE_WORKING_KQUEUE
@@ -107,7 +107,7 @@ static const struct eventop *eventops[] = {
 #ifdef EVENT__HAVE_WORKING_KQUEUE
        &kqops,
 #endif
-#ifdef EVENT__HAVE_EPOLL
+#if defined(EVENT__HAVE_EPOLL) && !defined(__HAIKU__)
        &epollops,
 #endif
 #ifdef EVENT__HAVE_DEVPOLL
kenz-gelsoft commented 1 year ago
 4:06.48 toolkit/library/build/libxul.so
 6:01.52 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: ../../../js/src/build/libjs_static.a(Unified_cpp_js_src9.o): in function `js::ThisThread::SetName(char const*)':
 6:01.52 /boot/home/src/firefox-102.9.0/js/src/threading/posix/PosixThread.cpp:126: undefined reference to `pthread_setname_np(_pthread_thread*, char const*)'
 6:04.00 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: ../../../js/src/build/libjs_static.a(Unified_cpp_js_src_util0.o): in function `js::GetNativeStackBaseImpl()':
 6:04.00 /boot/home/src/firefox-102.9.0/js/src/util/NativeStack.cpp:159: undefined reference to `pthread_getattr_np(_pthread_thread*, _pthread_attr**)'
 6:06.17 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: libxul.so: hidden symbol `_Z18pthread_getattr_npP15_pthread_threadPP13_pthread_attr' isn't defined
 6:06.17 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: final link failed: bad value
 6:06.55 collect2: error: ld returned 1 exit status
 6:06.55 clang-12: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
kenz-gelsoft commented 1 year ago

search pthread_setname_np in haiku source:

~/src/haiku> grep -R pthread_setname_np .
./headers/compatibility/gnu/pthread.h:extern int pthread_setname_np(pthread_t thread, const char* name);
./headers/private/libroot/pthread_private.h:int __pthread_setname_np(pthread_t thread, const char* name);
./src/system/libroot/posix/pthread/pthread.cpp:__pthread_setname_np(pthread_t thread, const char* name)
./src/system/libroot/posix/pthread/pthread.cpp:B_DEFINE_WEAK_ALIAS(__pthread_setname_np, pthread_setname_np);
./src/system/libroot/stubbed/libroot_stubs.c:void __pthread_setname_np() {}
./src/system/libroot/stubbed/libroot_stubs.c:void pthread_setname_np() {}
./src/system/libroot/stubbed/libroot_stubs_legacy.c:void __pthread_setname_np() {}
./src/system/libroot/stubbed/libroot_stubs_legacy.c:void pthread_setname_np() {}
kenz-gelsoft commented 1 year ago

declared like this in /boot/system/develop/headers/gnu/pthread.h

/*
 * Copyright 2019 Haiku, Inc. All Rights Reserved.
 * Distributed under the terms of the MIT License.
 */
#ifndef _GNU_PTHREAD_H_
#define _GNU_PTHREAD_H_

#include_next <pthread.h>

#ifdef _GNU_SOURCE

#ifdef __cplusplus
extern "C" {
#endif

extern int pthread_getattr_np(pthread_t thread, pthread_attr_t* attr);

extern int pthread_getname_np(pthread_t thread, char* buffer, size_t length);
extern int pthread_setname_np(pthread_t thread, const char* name);

#ifdef __cplusplus
}
#endif

#endif

#endif  /* _GNU_PTHREAD_H_ */
kenz-gelsoft commented 1 year ago

defining _GNU_SOURCE before pthread.h include didn't work well, so I've added function prototype as well

diff --git a/js/src/threading/posix/PosixThread.cpp b/js/src/threading/posix/PosixThread.cpp
index 35532e375b..e31b821a09 100644
--- a/js/src/threading/posix/PosixThread.cpp
+++ b/js/src/threading/posix/PosixThread.cpp
@@ -13,6 +13,13 @@
 #include "threading/posix/ThreadPlatformData.h"
 #include "threading/Thread.h"

+#ifdef __HAIKU__
+#  define _GNU_SOURCE
+extern int pthread_getattr_np(pthread_t thread, pthread_attr_t* attr);
+extern int pthread_getname_np(pthread_t thread, char* buffer, size_t length);
+extern int pthread_setname_np(pthread_t thread, const char* name);
+#endif
+
 namespace js {

 inline ThreadId::PlatformData* ThreadId::platformData() {
diff --git a/js/src/threading/posix/ThreadPlatformData.h b/js/src/threading/posix/ThreadPlatformData.h
index 2ac197d771..237f0c3c63 100644
--- a/js/src/threading/posix/ThreadPlatformData.h
+++ b/js/src/threading/posix/ThreadPlatformData.h
@@ -7,6 +7,9 @@
 #ifndef threading_posix_PlatformData_h
 #define threading_posix_PlatformData_h

+#ifdef __HAIKU__
+#  define _GNU_SOURCE
+#endif
 #include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/js/src/util/NativeStack.cpp b/js/src/util/NativeStack.cpp
index 4e4189d397..583491af20 100644
--- a/js/src/util/NativeStack.cpp
+++ b/js/src/util/NativeStack.cpp
@@ -24,7 +24,7 @@
 #    include <sys/types.h>
 #    include <unistd.h>
 #  endif
-#  if defined(XP_LINUX) && !defined(ANDROID) && defined(__GLIBC__)
+#  if (defined(XP_LINUX) || defined(__HAIKU__)) && !defined(ANDROID) && defined(__GLIBC__)
 #    include <dlfcn.h>
 #    include <sys/syscall.h>
 #    include <sys/types.h>
@@ -35,6 +35,14 @@
 #  error "Unsupported platform"
 #endif

+#ifdef __HAIKU__
+#  define _GNU_SOURCE
+extern int pthread_getattr_np(pthread_t thread, pthread_attr_t* attr);
+
+extern int pthread_getname_np(pthread_t thread, char* buffer, size_t length);
+extern int pthread_setname_np(pthread_t thread, const char* name);
+#endif
+
 #include "js/friend/StackLimits.h"  // JS_STACK_GROWTH_DIRECTION

 #if defined(XP_WIN)
kenz-gelsoft commented 1 year ago

or commented out if it looks trivial

diff --git a/third_party/dav1d/src/thread.h b/third_party/dav1d/src/thread.h
index b091e4f26d..b0226f3dcc 100644
--- a/third_party/dav1d/src/thread.h
+++ b/third_party/dav1d/src/thread.h
@@ -169,14 +169,14 @@ static inline void dav1d_set_thread_name(const char *const name) {
     pthread_setname_np(pthread_self(), "%s", (void*)name);
 }

-#elif defined(__HAIKU__)
-
-#include <os/kernel/OS.h>
-
-static inline void dav1d_set_thread_name(const char *const name) {
-    rename_thread(find_thread(NULL), name);
-}
-
+//#elif defined(__HAIKU__)
+//
+//#include <os/kernel/OS.h>
+//
+//static inline void dav1d_set_thread_name(const char *const name) {
+//    rename_thread(find_thread(NULL), name);
+//}
+//
 #else

 #define dav1d_set_thread_name(name) do {} while (0)
kenz-gelsoft commented 1 year ago

at least, in Haiku header it has "C" linkage, but my function prototype declaration is not.

try fixting it

kenz-gelsoft commented 1 year ago

diff of these files are now:

diff --git a/js/src/threading/posix/PosixThread.cpp b/js/src/threading/posix/PosixThread.cpp
index 35532e375b..8c201d139b 100644
--- a/js/src/threading/posix/PosixThread.cpp
+++ b/js/src/threading/posix/PosixThread.cpp
@@ -13,6 +13,15 @@
 #include "threading/posix/ThreadPlatformData.h"
 #include "threading/Thread.h"

+#ifdef __HAIKU__
+#  define _GNU_SOURCE
+extern "C" {
+  extern int pthread_getattr_np(pthread_t thread, pthread_attr_t* attr);
+  extern int pthread_getname_np(pthread_t thread, char* buffer, size_t length);
+  extern int pthread_setname_np(pthread_t thread, const char* name);
+}
+#endif
+
 namespace js {

 inline ThreadId::PlatformData* ThreadId::platformData() {
diff --git a/js/src/util/NativeStack.cpp b/js/src/util/NativeStack.cpp
index 4e4189d397..4260cb60d6 100644
--- a/js/src/util/NativeStack.cpp
+++ b/js/src/util/NativeStack.cpp
@@ -24,7 +24,7 @@
 #    include <sys/types.h>
 #    include <unistd.h>
 #  endif
-#  if defined(XP_LINUX) && !defined(ANDROID) && defined(__GLIBC__)
+#  if (defined(XP_LINUX) || defined(__HAIKU__)) && !defined(ANDROID) && defined(__GLIBC__)
 #    include <dlfcn.h>
 #    include <sys/syscall.h>
 #    include <sys/types.h>
@@ -35,6 +35,15 @@
 #  error "Unsupported platform"
 #endif

+#ifdef __HAIKU__
+#  define _GNU_SOURCE
+extern "C" {
+  extern int pthread_getattr_np(pthread_t thread, pthread_attr_t* attr);
+  extern int pthread_getname_np(pthread_t thread, char* buffer, size_t length);
+  extern int pthread_setname_np(pthread_t thread, const char* name);
+}
+#endif
+
 #include "js/friend/StackLimits.h"  // JS_STACK_GROWTH_DIRECTION

 #if defined(XP_WIN)
kenz-gelsoft commented 1 year ago

Hmm... it didn't change the situation...

/../../js/src/build/libjs_static.a(Unified_cpp_js_src9.o): in function `js::ThisThread::SetName(char const*)':
 2:12.83 /boot/home/src/firefox-102.9.0/js/src/threading/posix/PosixThread.cpp:128: undefined reference to `pthread_setname_np'
 2:14.73 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: ../../../js/src/build/libjs_static.a(Unified_cpp_js_src_util0.o): in function `js::GetNativeStackBaseImpl()':
 2:14.73 /boot/home/src/firefox-102.9.0/js/src/util/NativeStack.cpp:160: undefined reference to `pthread_getattr_np'
 2:19.27 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: libxul.so: hidden symbol `pthread_getattr_np' isn't defined
 2:19.27 /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: final link failed: bad value
 2:19.65 collect2: error: ld returned 1 exit status
 2:19.65 clang-12: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
kenz-gelsoft commented 1 year ago

setting/gettint thread name may not be mandatory.

try stub out those for now...

kenz-gelsoft commented 1 year ago

after some hackarounds, I finally built (maybe broken) firefox binary.

 2:54.26 Executing "/bin/node /boot/home/src/firefox-102.9.0/devtools/client/shared/build/build.js /boot/home/src/firefox-102.9.0/devtools/client/debugger/src/workers/search/index.js /boot/home/src/firefox-102.9.0/obj-x86_64-unknown-haiku/dist/bin/browser/chrome/devtools/modules/devtools/client/debugger/src/workers/search"
 2:54.67 ./spidermonkey_checks.stub
 2:55.17 ./fake_remote_dafsa.bin.stub
 2:56.16 ./last_modified.json.stub
 2:56.38 ./feature_definitions.json.stub
 2:56.51 ./FeatureManifest.js.stub
 2:56.52 ./ScalarArtifactDefinitions.json.stub
 2:56.55 ./EventArtifactDefinitions.json.stub
 2:56.70 ./glean_checks.stub
 2:58.21 ./dependentlibs.list.stub
 2:58.22 ./multilocale.txt.stub
 2:59.34 ./built_in_addons.json.stub
 3:03.65 ✨ Your metrics are Glean! ✨
 3:12.28 TEST-PASS | check_spidermonkey_style.py | ok
 3:13.66 toolkit/locales/update.locale.stub
 3:13.66 toolkit/locales/locale.ini.stub
 3:13.81 TEST-PASS | check_macroassembler_style.py | ok
 3:14.19 TEST-PASS | check_js_opcode.py | ok
 3:21.08 Packaging quitter@mozilla.org.xpi...
 3:21.57 190 compiler warnings present.
 3:22.37 Overall system resources - Wall time: 200s; CPU: 0%; Read bytes: 0; Write bytes: 0; Read time: 0; Write time: 0
To view resource usage of the build, run |mach resource-usage|.
 3:22.57 Your build was successful!
To take your build for a test drive, run: |mach run|
For more information on what to do now, see https://firefox-source-docs.mozilla.org/setup/contributing_code.html