darlinghq / darling

Darwin/macOS emulation layer for Linux
http://www.darlinghq.org
GNU General Public License v3.0
11.45k stars 445 forks source link

Error building LKM on Ubuntu 20.04 #1012

Closed nolanbconaway closed 2 years ago

nolanbconaway commented 3 years ago

Build Log I can't tell exactly what the relevant error is, but error: implicit declaration of function ‘os_add_overflow’; did you mean ‘os_add3_overflow’? [-Werror=implicit-function-declaration] is the last red thing in my terminal.

I'll also say that there were countless warnings while running make, and not the ssl ones covered by the [docs]https://docs.darlinghq.org/build-instructions.html.

I'm very sorry i cannot be more helpful about debuggin this; it's a little out of my zone! Here's hoping it's a known issue with an easy fix that someone can link to.

Here is the build log:

Built target migcom
Built target migexe
Scanning dependencies of target lkm_generate
Generating osfmk/mach/upl_user.c, osfmk/mach/upl.h, osfmk/mach/upl_server.c, osfmk/mach/upl_server.h, osfmk/mach/uplXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/host_notify_reply_user.c, osfmk/mach/host_notify_reply.h, osfmk/mach/host_notify_reply_server.c, osfmk/mach/host_notify_reply_server.h, osfmk/mach/host_notify_replyXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/vm32_map_user.c, osfmk/mach/vm32_map.h, osfmk/mach/vm32_map_server.c, osfmk/mach/vm32_map_server.h, osfmk/mach/vm32_mapXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/mach_notify_user.c, osfmk/mach/mach_notify.h, osfmk/mach/mach_notify_server.c, osfmk/mach/mach_notify_server.h, osfmk/mach/mach_notifyXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/mach_voucher_attr_control_user.c, osfmk/mach/mach_voucher_attr_control.h, osfmk/mach/mach_voucher_attr_control_server.c, osfmk/mach/mach_voucher_attr_control_server.h, osfmk/mach/mach_voucher_attr_controlXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/memory_entry_user.c, osfmk/mach/memory_entry.h, osfmk/mach/memory_entry_server.c, osfmk/mach/memory_entry_server.h, osfmk/mach/memory_entryXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/memory_object_control_user.c, osfmk/mach/memory_object_control.h, osfmk/mach/memory_object_control_server.c, osfmk/mach/memory_object_control_server.h, osfmk/mach/memory_object_controlXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/memory_object_user.c, osfmk/mach/memory_object.h, osfmk/mach/memory_object_server.c, osfmk/mach/memory_object_server.h, osfmk/mach/memory_objectXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/memory_object_default_user.c, osfmk/mach/memory_object_default.h, osfmk/mach/memory_object_default_server.c, osfmk/mach/memory_object_default_server.h, osfmk/mach/memory_object_defaultXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/mach_voucher_user.c, osfmk/mach/mach_voucher.h, osfmk/mach/mach_voucher_server.c, osfmk/mach/mach_voucher_server.h, osfmk/mach/mach_voucherXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/vm_map_user.c, osfmk/mach/vm_map.h, osfmk/mach/vm_map_server.c, osfmk/mach/vm_map_server.h, osfmk/mach/vm_mapXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/resource_notify_user.c, osfmk/mach/resource_notify.h, osfmk/mach/resource_notify_server.c, osfmk/mach/resource_notify_server.h, osfmk/mach/resource_notifyXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/restartable_user.c, osfmk/mach/restartable.h, osfmk/mach/restartable_server.c, osfmk/mach/restartable_server.h, osfmk/mach/restartableXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/exc_user.c, osfmk/mach/exc.h, osfmk/mach/exc_server.c, osfmk/mach/exc_server.h, osfmk/mach/excXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/mach_exc_user.c, osfmk/mach/mach_exc.h, osfmk/mach/mach_exc_server.c, osfmk/mach/mach_exc_server.h, osfmk/mach/mach_excXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/notify_user.c, osfmk/mach/notify.h, osfmk/mach/notify_server.c, osfmk/mach/notify_server.h, osfmk/mach/notifyXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/task_user.c, osfmk/mach/task.h, osfmk/mach/task_server.c, osfmk/mach/task_server.h, osfmk/mach/taskXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/clock_user.c, osfmk/mach/clock.h, osfmk/mach/clock_server.c, osfmk/mach/clock_server.h, osfmk/mach/clockXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/clock_priv_user.c, osfmk/mach/clock_priv.h, osfmk/mach/clock_priv_server.c, osfmk/mach/clock_priv_server.h, osfmk/mach/clock_privXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/processor_user.c, osfmk/mach/processor.h, osfmk/mach/processor_server.c, osfmk/mach/processor_server.h, osfmk/mach/processorXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/host_priv_user.c, osfmk/mach/host_priv.h, osfmk/mach/host_priv_server.c, osfmk/mach/host_priv_server.h, osfmk/mach/host_privXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/host_security_user.c, osfmk/mach/host_security.h, osfmk/mach/host_security_server.c, osfmk/mach/host_security_server.h, osfmk/mach/host_securityXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/lock_set_user.c, osfmk/mach/lock_set.h, osfmk/mach/lock_set_server.c, osfmk/mach/lock_set_server.h, osfmk/mach/lock_setXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/mach_port_user.c, osfmk/mach/mach_port.h, osfmk/mach/mach_port_server.c, osfmk/mach/mach_port_server.h, osfmk/mach/mach_portXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/mach_vm_user.c, osfmk/mach/mach_vm.h, osfmk/mach/mach_vm_server.c, osfmk/mach/mach_vm_server.h, osfmk/mach/mach_vmXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/mach_host_user.c, osfmk/mach/mach_host.h, osfmk/mach/mach_host_server.c, osfmk/mach/mach_host_server.h, osfmk/mach/mach_hostXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/processor_set_user.c, osfmk/mach/processor_set.h, osfmk/mach/processor_set_server.c, osfmk/mach/processor_set_server.h, osfmk/mach/processor_setXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/thread_act_user.c, osfmk/mach/thread_act.h, osfmk/mach/thread_act_server.c, osfmk/mach/thread_act_server.h, osfmk/mach/thread_actXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/mach/clock_reply_user.c, osfmk/mach/clock_reply.h, osfmk/mach/clock_reply_server.c, osfmk/mach/clock_reply_server.h, osfmk/mach/clock_replyXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/device/device_user.c, osfmk/device/device.h, osfmk/device/device_server.c, osfmk/device/device_server.h, osfmk/device/deviceXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Generating osfmk/UserNotification/UNDReplyUser.c, osfmk/UserNotification/UNDReply.h, osfmk/UserNotification/UNDReplyServer.c, osfmk/UserNotification/UNDReplyServer.h, osfmk/UserNotification/UNDReplyXtraceMig.c
clang: warning: argument unused during compilation: '-arch i386' [-Wunused-command-line-argument]
Built target lkm_generate
Built target rtsig
Built target rtsig_h
Scanning dependencies of target lkm
Building the Linux kernel module
make[4]: Entering directory '/home/squidward/Desktop/darling/src/external/lkm'
Running kernel version is 5.11.0-25-generic
rm -f darling-mach.mod.o
make -C /lib/modules/5.11.0-25-generic/build M=/home/squidward/Desktop/darling/src/external/lkm modules
make[5]: Entering directory '/usr/src/linux-headers-5.11.0-25-generic'
Running kernel version is 5.11.0-25-generic
Invoked by kernel build system, building for 5.11.0-25-generic
  CC [M]  /home/squidward/Desktop/darling/src/external/lkm/osfmk/ipc/ipc_entry.o
In file included from /home/squidward/Desktop/darling/src/external/lkm/osfmk/mach/port.h:90,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/ipc/ipc_entry.c:74:
/home/squidward/Desktop/darling/src/external/lkm/EXTERNAL_HEADERS/stdint.h:137: warning: "UINTPTR_MAX" redefined
  137 | #define UINTPTR_MAX   UINT64_MAX
      | 
In file included from ./include/linux/limits.h:7,
                 from ./include/linux/kernel.h:6,
                 from ./include/linux/list.h:9,
                 from ./include/linux/module.h:12,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/duct/duct.h:50,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/ipc/ipc_entry.c:67:
./include/vdso/limits.h:17: note: this is the location of the previous definition
   17 | #define UINTPTR_MAX ULONG_MAX
      | 
In file included from /home/squidward/Desktop/darling/src/external/lkm/osfmk/mach/vm_param.h:79,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/mach/mach_types.h:115,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/kern/clock.h:38,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/kern/sched_prim.h:72,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/ipc/ipc_entry.c:76:
/home/squidward/Desktop/darling/src/external/lkm/libkern/os/overflow.h:66:3: error: #error os_overflow expects type-generic builtins
   66 | # error os_overflow expects type-generic builtins
      |   ^~~~~
In file included from /home/squidward/Desktop/darling/src/external/lkm/osfmk/mach/mach_types.h:115,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/kern/clock.h:38,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/kern/sched_prim.h:72,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/ipc/ipc_entry.c:76:
/home/squidward/Desktop/darling/src/external/lkm/osfmk/mach/vm_param.h: In function ‘mach_vm_round_page_overflow’:
/home/squidward/Desktop/darling/src/external/lkm/osfmk/mach/vm_param.h:126:23: error: implicit declaration of function ‘os_add_overflow’; did you mean ‘os_add3_overflow’? [-Werror=implicit-function-declaration]
  126 |          bool __ovr = os_add_overflow(in, (__typeof__(*out))PAGE_MASK, out); \
      |                       ^~~~~~~~~~~~~~~
/home/squidward/Desktop/darling/src/external/lkm/osfmk/mach/vm_param.h:134:9: note: in expansion of macro ‘round_page_overflow’
  134 |  return round_page_overflow(in, out);
      |         ^~~~~~~~~~~~~~~~~~~
In file included from /home/squidward/Desktop/darling/src/external/lkm/bsd/sys/event.h:674,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/ipc/ipc_mqueue.h:82,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/ipc/ipc_port.h:91,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/kern/task.h:126,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/kern/thread.h:122,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/kern/sched_prim.h:74,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/ipc/ipc_entry.c:76:
/home/squidward/Desktop/darling/src/external/lkm/bsd/sys/fcntl.h: At top level:
/home/squidward/Desktop/darling/src/external/lkm/bsd/sys/fcntl.h:145: warning: "AT_EACCESS" redefined
  145 | #define AT_EACCESS              0x0010  /* Use effective ids in access check */
      | 
In file included from ./include/linux/fcntl.h:6,
                 from ./include/linux/fs.h:26,
                 from ./include/linux/huge_mm.h:8,
                 from ./include/linux/mm.h:703,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/duct/duct.h:55,
                 from /home/squidward/Desktop/darling/src/external/lkm/osfmk/ipc/ipc_entry.c:67:
./include/uapi/linux/fcntl.h:99: note: this is the location of the previous definition
   99 | #define AT_EACCESS  0x200 /* Test access permitted for
      | 
cc1: some warnings being treated as errors
make[6]: *** [scripts/Makefile.build:287: /home/squidward/Desktop/darling/src/external/lkm/osfmk/ipc/ipc_entry.o] Error 1
make[5]: *** [Makefile:1848: /home/squidward/Desktop/darling/src/external/lkm] Error 2
make[5]: Leaving directory '/usr/src/linux-headers-5.11.0-25-generic'
make[4]: *** [Makefile:615: default] Error 2
make[4]: Leaving directory '/home/squidward/Desktop/darling/src/external/lkm'
make[3]: *** [src/external/lkm/CMakeFiles/lkm.dir/build.make:58: src/external/lkm/CMakeFiles/lkm] Error 2
make[2]: *** [CMakeFiles/Makefile2:61570: src/external/lkm/CMakeFiles/lkm.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:61577: src/external/lkm/CMakeFiles/lkm.dir/rule] Error 2
make: *** [Makefile:20132: lkm] Error 2

System Information What system are you building with?

Ubuntu 20.04.2 LTS

Software Version
Clang 10.0.0-4ubuntu1
CMake cmake version 3.16.3
Linux Kernel 5.11.0-25-generic
Darling Pulled this afternoon (Aug 20 NYC time); 9393db2c6ed530acaa2a4a933c391f1363fea1e8
tresf commented 3 years ago

I think this is a duplicate of #978, but that one's closed.

I managed to get it to compile with the following patch:

File: darling/src/external/lkm/libkern/os/overflow.h

- #if __has_builtin(__builtin_add_overflow) && \
-          __has_builtin(__builtin_sub_overflow) && \
-          __has_builtin(__builtin_mul_overflow)
+ #if true

I suspect one of the above conditions is failing. I even downloaded the latest Clang tarball and it still fails at the exact same spot.

The brute-force patch seems to work. Then once the LKM is installed, darling shell seems functional:

Darling [/Volumes/SystemRoot/home/ubuntu/darling/build]$ security list-keychain
    "/Library/Keychains/System.keychain"
nolanbconaway commented 3 years ago

That did it for me as well! Thanks! Let me know if this should be left open for others!

facekapow commented 2 years ago

Please try the solution described here and let me know if it works for you.

JSorella commented 2 years ago

Hi, I had this very same issue and I have solved it as described above (editing the file overflow.h).

Thanks for posting this solution!! @tresf

facekapow commented 2 years ago

Closing this as we no longer use a kernel module.