bblanchon / pdfium-binaries

📰 Binary distribution of PDFium
789 stars 166 forks source link

Draft: Start of MUSL ARM support #133

Closed jerbob92 closed 7 months ago

bblanchon commented 7 months ago

Cool! Musl builds are very long, so I won't have the time to test it today. I'll have a look at it on Monday.

bblanchon commented 7 months ago

I'm getting the following error in the test step for arm64:

[ 50%] Linking C executable example
/usr/lib/gcc-cross/aarch64-linux-gnu/10/../../../../aarch64-linux-gnu/bin/ld: warning: libc.so, needed by /data/pdfium-binaries/staging/lib/libpdfium.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/10/../../../../aarch64-linux-gnu/bin/ld: example: hidden symbol `atexit' in /usr/aarch64-linux-gnu/lib/libc_nonshared.a(atexit.oS) is referenced by DSO
/usr/lib/gcc-cross/aarch64-linux-gnu/10/../../../../aarch64-linux-gnu/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status

Did you get it too?

bblanchon commented 7 months ago

And for the arm build, I get:

FAILED: obj/third_party/abseil-cpp/absl/debugging/stacktrace/stacktrace.o 
arm-linux-musleabihf-g++ -MMD -MF obj/third_party/abseil-cpp/absl/debugging/stacktrace/stacktrace.o.d -DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_OZONE=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DCR_SYSROOT_KEY=20230611T210420Z-2 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DABSL_ALLOCATOR_NOTHROW=1 -I.. -Igen -I../third_party/abseil-cpp -fno-ident -fno-strict-aliasing -fstack-protector -funwind-tables -fPIC -pipe -pthread -march=armv7-a -mfloat-abi=hard -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -mfpu=neon -mthumb -O2 -fdata-sections -ffunction-sections -fno-math-errno -fno-omit-frame-pointer -g0 -fvisibility=hidden -Wno-psabi -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wno-deprecated-declarations -Wno-comments -Wno-packed-not-aligned -Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi -std=gnu++2a -fno-exceptions -fno-rtti --sysroot=../build/linux/debian_bullseye_armhf-sysroot -fvisibility-inlines-hidden -std=gnu++17 -Wno-narrowing -Wno-class-memaccess -c ../third_party/abseil-cpp/absl/debugging/stacktrace.cc -o obj/third_party/abseil-cpp/absl/debugging/stacktrace/stacktrace.o
In file included from ../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:23,
                 from ../third_party/abseil-cpp/absl/debugging/stacktrace.cc:46:
../build/linux/debian_bullseye_armhf-sysroot/usr/include/execinfo.h:23:1: error: ‘__BEGIN_DECLS’ does not name a type
   23 | __BEGIN_DECLS
      | ^~~~~~~~~~~~~
../build/linux/debian_bullseye_armhf-sysroot/usr/include/execinfo.h:33:6: error: expected initializer before ‘__THROW’
   33 |      __THROW __nonnull ((1));
      |      ^~~~~~~
../build/linux/debian_bullseye_armhf-sysroot/usr/include/execinfo.h:39:6: error: expected initializer before ‘__THROW’
   39 |      __THROW __nonnull ((1));
      |      ^~~~~~~
../build/linux/debian_bullseye_armhf-sysroot/usr/include/execinfo.h:41:1: error: ‘__END_DECLS’ does not name a type
   41 | __END_DECLS
      | ^~~~~~~~~~~
In file included from ../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:25,
                 from ../third_party/abseil-cpp/absl/debugging/stacktrace.cc:46:
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:77:11: error: ‘memchr’ has not been declared in ‘::’
   77 |   using ::memchr;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:78:11: error: ‘memcmp’ has not been declared in ‘::’
   78 |   using ::memcmp;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:79:11: error: ‘memcpy’ has not been declared in ‘::’
   79 |   using ::memcpy;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:80:11: error: ‘memmove’ has not been declared in ‘::’
   80 |   using ::memmove;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:81:11: error: ‘memset’ has not been declared in ‘::’
   81 |   using ::memset;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:82:11: error: ‘strcat’ has not been declared in ‘::’
   82 |   using ::strcat;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:83:11: error: ‘strcmp’ has not been declared in ‘::’
   83 |   using ::strcmp;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:84:11: error: ‘strcoll’ has not been declared in ‘::’
   84 |   using ::strcoll;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:85:11: error: ‘strcpy’ has not been declared in ‘::’
   85 |   using ::strcpy;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:86:11: error: ‘strcspn’ has not been declared in ‘::’
   86 |   using ::strcspn;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:87:11: error: ‘strerror’ has not been declared in ‘::’
   87 |   using ::strerror;
      |           ^~~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:88:11: error: ‘strlen’ has not been declared in ‘::’
   88 |   using ::strlen;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:89:11: error: ‘strncat’ has not been declared in ‘::’
   89 |   using ::strncat;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:90:11: error: ‘strncmp’ has not been declared in ‘::’
   90 |   using ::strncmp;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:91:11: error: ‘strncpy’ has not been declared in ‘::’
   91 |   using ::strncpy;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:92:11: error: ‘strspn’ has not been declared in ‘::’
   92 |   using ::strspn;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:93:11: error: ‘strtok’ has not been declared in ‘::’
   93 |   using ::strtok;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:94:11: error: ‘strxfrm’ has not been declared in ‘::’
   94 |   using ::strxfrm;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:95:11: error: ‘strchr’ has not been declared in ‘::’
   95 |   using ::strchr;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:96:11: error: ‘strpbrk’ has not been declared in ‘::’
   96 |   using ::strpbrk;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:97:11: error: ‘strrchr’ has not been declared in ‘::’
   97 |   using ::strrchr;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:98:11: error: ‘strstr’ has not been declared in ‘::’
   98 |   using ::strstr;
      |           ^~~~~~
In file included from ../third_party/abseil-cpp/absl/debugging/stacktrace.cc:46:
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc: In function ‘int UnwindImpl(void**, int*, int, int, const void*, int*)’:
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:60:10: error: there are no arguments to ‘backtrace’ that depend on a template parameter, so a declaration of ‘backtrace’ must be available [-fpermissive]
   60 |   size = backtrace(stack, kStackLength);
      |          ^~~~~~~~~
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:60:10: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:72:5: error: there are no arguments to ‘memset’ that depend on a template parameter, so a declaration of ‘memset’ must be available [-fpermissive]
   72 |     memset(sizes, 0, sizeof(*sizes) * static_cast<size_t>(result_count));
      |     ^~~~~~
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc: In instantiation of ‘int UnwindImpl(void**, int*, int, int, const void*, int*) [with bool IS_STACK_FRAMES = false; bool IS_WITH_CONTEXT = false]’:
../third_party/abseil-cpp/absl/debugging/stacktrace.cc:124:12:   required from here
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:60:19: error: ‘backtrace’ was not declared in this scope
   60 |   size = backtrace(stack, kStackLength);
      |          ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:72:11: error: ‘memset’ was not declared in this scope
   72 |     memset(sizes, 0, sizeof(*sizes) * static_cast<size_t>(result_count));
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:26:1: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
   25 | #include <cstring>
  +++ |+#include <cstring>
   26 | 
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc: In instantiation of ‘int UnwindImpl(void**, int*, int, int, const void*, int*) [with bool IS_STACK_FRAMES = false; bool IS_WITH_CONTEXT = true]’:
../third_party/abseil-cpp/absl/debugging/stacktrace.cc:126:12:   required from here
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:60:19: error: ‘backtrace’ was not declared in this scope
   60 |   size = backtrace(stack, kStackLength);
      |          ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:72:11: error: ‘memset’ was not declared in this scope
   72 |     memset(sizes, 0, sizeof(*sizes) * static_cast<size_t>(result_count));
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:72:11: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc: In instantiation of ‘int UnwindImpl(void**, int*, int, int, const void*, int*) [with bool IS_STACK_FRAMES = true; bool IS_WITH_CONTEXT = false]’:
../third_party/abseil-cpp/absl/debugging/stacktrace.cc:130:12:   required from here
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:60:19: error: ‘backtrace’ was not declared in this scope
   60 |   size = backtrace(stack, kStackLength);
      |          ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:72:11: error: ‘memset’ was not declared in this scope
   72 |     memset(sizes, 0, sizeof(*sizes) * static_cast<size_t>(result_count));
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:72:11: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc: In instantiation of ‘int UnwindImpl(void**, int*, int, int, const void*, int*) [with bool IS_STACK_FRAMES = true; bool IS_WITH_CONTEXT = true]’:
../third_party/abseil-cpp/absl/debugging/stacktrace.cc:132:12:   required from here
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:60:19: error: ‘backtrace’ was not declared in this scope
   60 |   size = backtrace(stack, kStackLength);
      |          ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:72:11: error: ‘memset’ was not declared in this scope
   72 |     memset(sizes, 0, sizeof(*sizes) * static_cast<size_t>(result_count));
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:72:11: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[545/1016] CC obj/third_party/fx_libopenjpeg/t1.o
ninja: build stopped: subcommand failed.

I guess you had the same error?

jerbob92 commented 7 months ago

That's odd, the arm64 test step worked fine for me after I made the changes to steps/08-test.sh that are in this PR.

For ARM I indeed had the same issue. I did get it to go a bit further by patching abseil-cpp a bit because it didn't seem to include the generic ARM debug/stacktrace include, but it is available in the repo. But I ran into other issues after that.

Do you run these builds locally or in some virtual build environment?

bblanchon commented 7 months ago

I suggest we focus on the arm64 build for the moment and let the arm build aside.

I ran these builds in a fresh EC2 instance. I didn't notice anything abnormal that could explain the libc.so not found. From what I saw, all the objects were built with Musl's gcc. I compared the gcc command lines in x86 and arm64, and they were perfectly consistent.

BTW, I think that the packages g++-10 and g++-10-multilib (and therefore the update-alternatives call) are not required for this build.

jerbob92 commented 7 months ago

I suggest we focus on the arm64 build for the moment and let the arm build aside.

That's fine with me.

BTW, I think that the packages g++-10 and g++-10-multilib (and therefore the update-alternatives call) are not required for this build.

That's possible indeed, I mainly looked at the normal ARM builds, and I remember that I did have to install some stuff to make it work, but I don't know exactly. I will also try this in a fresh VM.

jerbob92 commented 7 months ago

I'm getting the same error. It seems to be related to the options -static-libgcc -static-libstdc++.

jerbob92 commented 7 months ago

@bblanchon Fixed and pushed. It uses Alpine GCC now to compile the example.

Validated with the following docker file:

FROM ubuntu:22.04

RUN apt update && apt install -y curl git sudo python3 file

RUN git clone --branch="feature/musl-arm-support" https://github.com/jerbob92/pdfium-binaries.git

WORKDIR "/pdfium-binaries"

RUN ./build.sh -b chromium/6043 -m linux arm64

Do you know why the g++-10/g++-10-multilib package are needed for the other musl packages, and why they need to do update-alternatives? I'd say they would also use the Alpine GCC?

bblanchon commented 7 months ago

Do you know why the g++-10/g++-10-multilib package are needed for the other musl packages

If I remove g++-10-multilib for the x86 build, I get the following error when V8 is enabled:

[1359/4551] CXX x86/obj/third_party/abseil-cpp/absl/base/base/cycleclock.o
FAILED: x86/obj/third_party/abseil-cpp/absl/base/base/cycleclock.o 
g++ -MMD -MF x86/obj/third_party/abseil-cpp/absl/base/base/cycleclock.o.d -DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_OZONE=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DCR_SYSROOT_KEY=20230611T210420Z-2 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DABSL_ALLOCATOR_NOTHROW=1 -I.. -Ix86/gen -I../third_party/abseil-cpp -fno-ident -fno-strict-aliasing -fno-stack-protector -funwind-tables -fPIC -pipe -pthread -m32 -mfpmath=sse -msse3 -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -O2 -fdata-sections -ffunction-sections -fno-math-errno -fno-omit-frame-pointer -g0 -fvisibility=hidden -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wno-deprecated-declarations -Wno-comments -Wno-packed-not-aligned -Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi -std=gnu++2a -fno-exceptions -fno-rtti --sysroot=../build/linux/debian_bullseye_i386-sysroot -fvisibility-inlines-hidden -std=gnu++17 -Wno-narrowing -Wno-class-memaccess -c ../third_party/abseil-cpp/absl/base/internal/cycleclock.cc -o x86/obj/third_party/abseil-cpp/absl/base/base/cycleclock.o
In file included from /usr/include/c++/10/atomic:41,
                 from ../third_party/abseil-cpp/absl/base/internal/cycleclock.h:45,
                 from ../third_party/abseil-cpp/absl/base/internal/cycleclock.cc:23:
/usr/include/c++/10/bits/atomic_base.h:35:10: fatal error: bits/c++config.h: No such file or directory
   35 | #include <bits/c++config.h>
      |          ^~~~~~~~~~~~~~~~~~
bblanchon commented 7 months ago

When I build musl x64 v8, I get the following error:

[1185/4454] CXX obj/v8/v8_libbase/cpu.o
FAILED: obj/v8/v8_libbase/cpu.o 
aarch64-linux-musl-g++ -MMD -MF obj/v8/v8_libbase/cpu.o.d -DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_OZONE=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DCR_SYSROOT_KEY=20230611T210420Z-2 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64 -DV8_ATOMIC_OBJECT_FIELD_WRITES -DV8_ENABLE_LAZY_SOURCE_POSITIONS -DV8_SHARED_RO_HEAP -DV8_WIN64_UNWINDING_INFO -DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH -DV8_ENABLE_CONTROL_FLOW_INTEGRITY -DV8_SHORT_BUILTIN_CALLS -DV8_EXTERNAL_CODE_SPACE -DV8_ENABLE_MAGLEV -DV8_ENABLE_TURBOFAN -DV8_ALLOCATION_FOLDING -DV8_ALLOCATION_SITE_TRACKING -DV8_ADVANCED_BIGINT_ALGORITHMS -DV8_USE_ZLIB -DV8_ENABLE_MAGLEV_GRAPH_PRINTER -DV8_ENABLE_EXTENSIBLE_RO_SNAPSHOT -DV8_COMPRESS_POINTERS -DV8_COMPRESS_POINTERS_IN_SHARED_CAGE -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_DEPRECATION_WARNINGS -DV8_IMMINENT_DEPRECATION_WARNINGS -DCPPGC_CAGED_HEAP -DCPPGC_YOUNG_GENERATION -DCPPGC_POINTER_COMPRESSION -DCPPGC_SLIM_WRITE_BARRIER -DV8_TARGET_ARCH_ARM64 -DV8_HAVE_TARGET_OS -DV8_TARGET_OS_LINUX -DV8_RUNTIME_CALL_STATS -I.. -Igen -I../v8 -I../v8/include -Igen/v8 -Igen/v8/include -Wall -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wno-deprecated-declarations -Wno-comments -Wno-packed-not-aligned -Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi -fno-ident -fno-strict-aliasing -fstack-protector -funwind-tables -fPIC -pipe -pthread -mbranch-protection=standard -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -fno-omit-frame-pointer -g0 -fvisibility=hidden -Wno-invalid-offsetof -Wno-strict-overflow -Wno-return-type -Wno-int-in-bool-context -Wno-deprecated -O3 -fdata-sections -ffunction-sections -fno-math-errno -Wno-narrowing -Wno-class-memaccess -std=gnu++2a -fno-exceptions -fno-rtti --sysroot=../build/linux/debian_bullseye_arm64-sysroot -fvisibility-inlines-hidden -std=gnu++17 -c ../v8/src/base/cpu.cc -o obj/v8/v8_libbase/cpu.o
../v8/src/base/cpu.cc: In function ‘std::tuple<unsigned int, unsigned int> v8::base::ReadELFHWCaps()’:
../v8/src/base/cpu.cc:179:33: error: ‘getauxval’ was not declared in this scope
  179 |   hwcap = static_cast<uint32_t>(getauxval(AT_HWCAP));
      |                                 ^~~~~~~~~

So I'll merge this PR without V8 and we'll fix this some other time.

jerbob92 commented 7 months ago

Do you know why the g++-10/g++-10-multilib package are needed for the other musl packages

If I remove g++-10-multilib for the x86 build, I get the following error when V8 is enabled:

[1359/4551] CXX x86/obj/third_party/abseil-cpp/absl/base/base/cycleclock.o
FAILED: x86/obj/third_party/abseil-cpp/absl/base/base/cycleclock.o 
g++ -MMD -MF x86/obj/third_party/abseil-cpp/absl/base/base/cycleclock.o.d -DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_OZONE=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DCR_SYSROOT_KEY=20230611T210420Z-2 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DABSL_ALLOCATOR_NOTHROW=1 -I.. -Ix86/gen -I../third_party/abseil-cpp -fno-ident -fno-strict-aliasing -fno-stack-protector -funwind-tables -fPIC -pipe -pthread -m32 -mfpmath=sse -msse3 -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -O2 -fdata-sections -ffunction-sections -fno-math-errno -fno-omit-frame-pointer -g0 -fvisibility=hidden -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wno-deprecated-declarations -Wno-comments -Wno-packed-not-aligned -Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi -std=gnu++2a -fno-exceptions -fno-rtti --sysroot=../build/linux/debian_bullseye_i386-sysroot -fvisibility-inlines-hidden -std=gnu++17 -Wno-narrowing -Wno-class-memaccess -c ../third_party/abseil-cpp/absl/base/internal/cycleclock.cc -o x86/obj/third_party/abseil-cpp/absl/base/base/cycleclock.o
In file included from /usr/include/c++/10/atomic:41,
                 from ../third_party/abseil-cpp/absl/base/internal/cycleclock.h:45,
                 from ../third_party/abseil-cpp/absl/base/internal/cycleclock.cc:23:
/usr/include/c++/10/bits/atomic_base.h:35:10: fatal error: bits/c++config.h: No such file or directory
   35 | #include <bits/c++config.h>
      |          ^~~~~~~~~~~~~~~~~~

When I look at that error, it looks like it's not using the g++ from musl?

bblanchon commented 7 months ago

When I look at that error, it looks like it's not using the g++ from musl?

So, either:

  1. the Musl v8 build is (silently) broken, or
  2. this object file doesn't use anything from libc, or
  3. it's part of a tool that runs on the host (but why would it need multilib then?)
jerbob92 commented 7 months ago

When I look at that error, it looks like it's not using the g++ from musl?

So, either:

  1. the Musl v8 build is (silently) broken, or
  2. this object file doesn't use anything from libc, or
  3. it's part of a tool that runs on the host (but why would it need multilib then?)

I'll see if I can figure it out. I'm starting to wonder now if we actually need -static-libgcc -static-libstdc++ or that this was just a way to include the libgcc/libstdc++ from the host in the binary, causing it to accidentally work on Alpine, but that it actually doesn't use musl to compile?

jerbob92 commented 7 months ago

I have looked into this, it seems to have to do with NASM, it tries to compile NASM on the host CPU/OS, but I'm not sure if that is what's supposed to happen. The reason why this is only needed for x86/x64: NASM is only for x86 and x64 so it's not included when you make ARM builds, so then you won't need g++-10 on the host.

I think NASM is supposed to run on the host to do these operations on the created files, so that's why it compiles it using the host g++?

bblanchon commented 7 months ago

This cannot be for Nasm since it's written in C, but it could be for another tool.

jerbob92 commented 7 months ago

But the error literally is:

[1/63] LINK x64/nasm
FAILED: x64/nasm 
"python3" "../build/toolchain/gcc_link_wrapper.py" --output="x64/nasm" -- g++ -Wl,--fatal-warnings -Wl,--build-id -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fuse-ld=gold -Wl,--threads -Wl,--thread-count=4 -m64 -Wl,-O2 -Wl,--gc-sections -rdynamic -Wl,-z,defs -Wl,--as-needed --sysroot=../build/linux/debian_bullseye_amd64-sysroot -pie -Wl,--disable-new-dtags -o "x64/nasm" -Wl,--start-group @"x64/nasm.rsp"  -Wl,--end-group  -latomic -ldl -lpthread -lrt 
Traceback (most recent call last):
  File "/pdfium-binaries/pdfium/out/../build/toolchain/gcc_link_wrapper.py", line 91, in <module>
    sys.exit(main())
  File "/pdfium-binaries/pdfium/out/../build/toolchain/gcc_link_wrapper.py", line 60, in main
    result = wrapper_utils.RunLinkWithOptionalMapFile(args.command, env=fast_env,
  File "/pdfium-binaries/pdfium/build/toolchain/wrapper_utils.py", line 78, in RunLinkWithOptionalMapFile
    result = subprocess.call(command, env=env)
  File "/usr/lib/python3.10/subprocess.py", line 345, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1863, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'g++'
ninja: build stopped: subcommand failed.

I think we might have to change the host toolchain to MUSL too, but then with the CPU of the host, so:

      echo 'host_toolchain = "//build/toolchain/linux/musl:x64"'
bblanchon commented 7 months ago

I see. I was talking about [1359/4551] CXX x86/obj/third_party/abseil-cpp/absl/base/base/cycleclock.o

I don't think we need to change the toolchain for the host, since it's working correctly.

jerbob92 commented 7 months ago

I see. I was talking about [1359/4551] CXX x86/obj/third_party/abseil-cpp/absl/base/base/cycleclock.o

I don't think we need to change the toolchain for the host, since it's working correctly.

Ah yes, I probably don't get to that error since I don't install g++-10/g++-10-multilib in my current test environment.

bblanchon commented 7 months ago

I just merged the branch. We can continue the conversation here, but it you want to push new code, please open a new PR. Thank you again, @jerbob92, for this contribution.

jerbob92 commented 7 months ago

Thanks for merging!

I think the v8 issue is related to the v8_snapshot_toolchain. This is what the docs say about it:

# The v8 snapshot needs to be built by code that is compiled with a
# toolchain that matches the bit-width of the target CPU, but runs on
# the host.

For musl it's currently set to:

       [ "$ENABLE_V8" == "true" ] && echo "v8_snapshot_toolchain = \"//build/toolchain/linux:$TARGET_CPU\""

I think this was added because of v8 automatically selecting current_toolchain for v8_snapshot_toolchain when the host arch and OS match the target arch and OS, which makes it build the v8 snapshot with the musl toolchain which won't work. However, I think this setting is wrong, I think it's only valid for x64 and x86 builds.

I think v8_snapshot_toolchain should be the following on a x64 host with the following target cpu:

Normally the v8 toolchain setup would automatically set this up, but since we override the toolchain, this is wrong on the first two options, and that's why we override v8_snapshot_toolchain manually, but this causes it to be wrong for the other CPU's too.

So what I think we must do is either patch the v8 snapshot_toolchain.gni to take is_musl into account, or change this line to something else so that it only overrides the v8_snapshot_toolchain when the target_cpu is x64 or x86.

jerbob92 commented 7 months ago

I have just tested the previous comment: I can confirm that with the following patch:

diff --git a/steps/05-configure.sh b/steps/05-configure.sh
index 634caca..ec41967 100755
--- a/steps/05-configure.sh
+++ b/steps/05-configure.sh
@@ -49,7 +49,13 @@ mkdir -p "$BUILD"
       echo 'is_musl = true'
       echo 'is_clang = false'
       echo 'use_custom_libcxx = false'
-      [ "$ENABLE_V8" == "true" ] && echo "v8_snapshot_toolchain = \"//build/toolchain/linux:$TARGET_CPU\""
+      if [ "$ENABLE_V8" == "true" ]; then
+          case "$TARGET_CPU" in
+            x86|x64)
+              echo "v8_snapshot_toolchain = \"//build/toolchain/linux:$TARGET_CPU\""
+              ;;
+          esac
+      fi
       ;;
   esac

I could successfully build musl v8 builds for: x86, x64 and arm64.

bblanchon commented 7 months ago
# The v8 snapshot needs to be built by code that is compiled with a
# toolchain that matches the bit-width of the target CPU, but runs on
# the host.

Right! I totally forgot about that part. I'll try your patch right away.

bblanchon commented 7 months ago

I still can't build v8 for arm64. I tried:

  1. removing v8_snapshot_toolchain as in the diff above
  2. setting v8_snapshot_toolchain to //build/toolchain/linux:clang_x64_v8_arm64
  3. setting host_toolchain to //build/toolchain/linux/x64 as you suggested earlier

In all cases, I still get the following error:

FAILED: obj/v8/v8_libbase/cpu.o 
aarch64-linux-musl-g++ -MMD -MF obj/v8/v8_libbase/cpu.o.d -DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_OZONE=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DCR_SYSROOT_KEY=20230611T210420Z-2 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64 -DV8_ATOMIC_OBJECT_FIELD_WRITES -DV8_ENABLE_LAZY_SOURCE_POSITIONS -DV8_SHARED_RO_HEAP -DV8_WIN64_UNWINDING_INFO -DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH -DV8_ENABLE_CONTROL_FLOW_INTEGRITY -DV8_SHORT_BUILTIN_CALLS -DV8_EXTERNAL_CODE_SPACE -DV8_ENABLE_MAGLEV -DV8_ENABLE_TURBOFAN -DV8_ALLOCATION_FOLDING -DV8_ALLOCATION_SITE_TRACKING -DV8_ADVANCED_BIGINT_ALGORITHMS -DV8_USE_ZLIB -DV8_ENABLE_MAGLEV_GRAPH_PRINTER -DV8_ENABLE_EXTENSIBLE_RO_SNAPSHOT -DV8_COMPRESS_POINTERS -DV8_COMPRESS_POINTERS_IN_SHARED_CAGE -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_DEPRECATION_WARNINGS -DV8_IMMINENT_DEPRECATION_WARNINGS -DCPPGC_CAGED_HEAP -DCPPGC_YOUNG_GENERATION -DCPPGC_POINTER_COMPRESSION -DCPPGC_SLIM_WRITE_BARRIER -DV8_TARGET_ARCH_ARM64 -DV8_HAVE_TARGET_OS -DV8_TARGET_OS_LINUX -DV8_RUNTIME_CALL_STATS -I.. -Igen -I../v8 -I../v8/include -Igen/v8 -Igen/v8/include -Wall -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wno-deprecated-declarations -Wno-comments -Wno-packed-not-aligned -Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi -fno-ident -fno-strict-aliasing -fstack-protector -funwind-tables -fPIC -pipe -pthread -mbranch-protection=standard -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -fno-omit-frame-pointer -g0 -fvisibility=hidden -Wno-invalid-offsetof -Wno-strict-overflow -Wno-return-type -Wno-int-in-bool-context -Wno-deprecated -O3 -fdata-sections -ffunction-sections -fno-math-errno -Wno-narrowing -Wno-class-memaccess -std=gnu++2a -fno-exceptions -fno-rtti --sysroot=../build/linux/debian_bullseye_arm64-sysroot -fvisibility-inlines-hidden -std=gnu++17 -c ../v8/src/base/cpu.cc -o obj/v8/v8_libbase/cpu.o
../v8/src/base/cpu.cc: In function ‘std::tuple<unsigned int, unsigned int> v8::base::ReadELFHWCaps()’:
../v8/src/base/cpu.cc:179:33: error: ‘getauxval’ was not declared in this scope
  179 |   hwcap = static_cast<uint32_t>(getauxval(AT_HWCAP));
      |                                 ^~~~~~~~~

My changes are in the branch musl-arm64-v8.

jerbob92 commented 7 months ago

Ok.... So.... My patch works for 6043 but not for 6056 :sob:

Which makes sense, as the code that broke this has been changed recently: https://chromium.googlesource.com/v8/v8.git/+/a8dcd14f7574775c0b04dd4d1e7d20f7195e6257%5E%21/src/base/cpu.cc

To me it feels like V8_GLIBC_PREREQ(2, 16) is missing in the changes, which was in there before. The following patch on v8 fixes it:

diff --git a/src/base/cpu.cc b/src/base/cpu.cc
index 9a21c10..57f880b 100644
--- a/src/base/cpu.cc
+++ b/src/base/cpu.cc
@@ -175,9 +175,9 @@ static V8_INLINE void __cpuid(int cpu_info[4], int info_type) {
 static std::tuple<uint32_t, uint32_t> ReadELFHWCaps() {
   uint32_t hwcap = 0;
   uint32_t hwcap2 = 0;
-#if defined(AT_HWCAP)
+#if (V8_GLIBC_PREREQ(2, 16) || V8_OS_ANDROID) && defined(AT_HWCAP)
   hwcap = static_cast<uint32_t>(getauxval(AT_HWCAP));
-#if defined(AT_HWCAP2)
+#if (V8_GLIBC_PREREQ(2, 16) || V8_OS_ANDROID) && defined(AT_HWCAP2)
   hwcap2 = static_cast<uint32_t>(getauxval(AT_HWCAP2));
 #endif  // AT_HWCAP2
 #else
@@ -196,7 +196,7 @@ static std::tuple<uint32_t, uint32_t> ReadELFHWCaps() {
         break;
       }
       if (entry.tag == AT_HWCAP) {
-        result = entry.value;
+        hwcap = entry.value;
         break;
       }
     }

I don't really know why this got merged in, it even contains compile errors because the variable result got removed in the changeset while it's still being written to. I have made a bug report here: https://bugs.chromium.org/p/v8/issues/detail?id=14381

bblanchon commented 7 months ago

Don't sweat it; it should be fixed soon. Temporary build failures are common; just see the number of commits starting with "Revert" in the build repo.

jerbob92 commented 7 months ago

@bblanchon the patch has been merged into v8 :)

bblanchon commented 6 months ago

Awesome, we just need to wait for PDFium to incorporate the change. Right now PDFium points to 1fb69d9, which is 25 commits behind the fix.

bblanchon commented 6 months ago

PDFium now points to 06aba4270, which includes your patch. Unfortunately, the build still fails:

FAILED: obj/third_party/abseil-cpp/absl/debugging/stacktrace/stacktrace.o 
arm-linux-musleabihf-g++ -MMD -MF obj/third_party/abseil-cpp/absl/debugging/stacktrace/stacktrace.o.d -DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_OZONE=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DCR_SYSROOT_KEY=20230611T210420Z-2 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DABSL_ALLOCATOR_NOTHROW=1 -I.. -Igen -I../third_party/abseil-cpp -fno-ident -fno-strict-aliasing -fstack-protector -funwind-tables -fPIC -pipe -pthread -march=armv7-a -mfloat-abi=hard -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -mfpu=neon -mthumb -O2 -fdata-sections -ffunction-sections -fno-math-errno -fno-omit-frame-pointer -g0 -fvisibility=hidden -Wno-psabi -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wno-deprecated-declarations -Wno-comments -Wno-packed-not-aligned -Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi -std=gnu++2a -fno-exceptions -fno-rtti --sysroot=../build/linux/debian_bullseye_armhf-sysroot -fvisibility-inlines-hidden -Wno-narrowing -Wno-class-memaccess -c ../third_party/abseil-cpp/absl/debugging/stacktrace.cc -o obj/third_party/abseil-cpp/absl/debugging/stacktrace/stacktrace.o
In file included from ../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:23,
                 from ../third_party/abseil-cpp/absl/debugging/stacktrace.cc:46:
../build/linux/debian_bullseye_armhf-sysroot/usr/include/execinfo.h:23:1: error: ‘__BEGIN_DECLS’ does not name a type
   23 | __BEGIN_DECLS
      | ^~~~~~~~~~~~~
../build/linux/debian_bullseye_armhf-sysroot/usr/include/execinfo.h:33:6: error: expected initializer before ‘__THROW’
   33 |      __THROW __nonnull ((1));
      |      ^~~~~~~
../build/linux/debian_bullseye_armhf-sysroot/usr/include/execinfo.h:39:6: error: expected initializer before ‘__THROW’
   39 |      __THROW __nonnull ((1));
      |      ^~~~~~~
../build/linux/debian_bullseye_armhf-sysroot/usr/include/execinfo.h:41:1: error: ‘__END_DECLS’ does not name a type
   41 | __END_DECLS
      | ^~~~~~~~~~~
In file included from ../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:25,
                 from ../third_party/abseil-cpp/absl/debugging/stacktrace.cc:46:
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:77:11: error: ‘memchr’ has not been declared in ‘::’
   77 |   using ::memchr;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:80:11: error: ‘memmove’ has not been declared in ‘::’
   80 |   using ::memmove;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:82:11: error: ‘strcat’ has not been declared in ‘::’
   82 |   using ::strcat;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:83:11: error: ‘strcmp’ has not been declared in ‘::’
   83 |   using ::strcmp;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:84:11: error: ‘strcoll’ has not been declared in ‘::’
   84 |   using ::strcoll;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:85:11: error: ‘strcpy’ has not been declared in ‘::’
   85 |   using ::strcpy;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:86:11: error: ‘strcspn’ has not been declared in ‘::’
   86 |   using ::strcspn;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:87:11: error: ‘strerror’ has not been declared in ‘::’
   87 |   using ::strerror;
      |           ^~~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:88:11: error: ‘strlen’ has not been declared in ‘::’
   88 |   using ::strlen;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:89:11: error: ‘strncat’ has not been declared in ‘::’
   89 |   using ::strncat;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:90:11: error: ‘strncmp’ has not been declared in ‘::’
   90 |   using ::strncmp;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:91:11: error: ‘strncpy’ has not been declared in ‘::’
   91 |   using ::strncpy;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:92:11: error: ‘strspn’ has not been declared in ‘::’
   92 |   using ::strspn;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:93:11: error: ‘strtok’ has not been declared in ‘::’
   93 |   using ::strtok;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:94:11: error: ‘strxfrm’ has not been declared in ‘::’
   94 |   using ::strxfrm;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:95:11: error: ‘strchr’ has not been declared in ‘::’
   95 |   using ::strchr;
      |           ^~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:96:11: error: ‘strpbrk’ has not been declared in ‘::’
   96 |   using ::strpbrk;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:97:11: error: ‘strrchr’ has not been declared in ‘::’
   97 |   using ::strrchr;
      |           ^~~~~~~
/data/pdfium-binaries/arm-linux-musleabihf-cross/arm-linux-musleabihf/include/c++/11.2.1/cstring:98:11: error: ‘strstr’ has not been declared in ‘::’
   98 |   using ::strstr;
      |           ^~~~~~
In file included from ../third_party/abseil-cpp/absl/debugging/stacktrace.cc:46:
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc: In function ‘int UnwindImpl(void**, int*, int, int, const void*, int*)’:
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:60:10: error: there are no arguments to ‘backtrace’ that depend on a template parameter, so a declaration of ‘backtrace’ must be available [-fpermissive]
   60 |   size = backtrace(stack, kStackLength);
      |          ^~~~~~~~~
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:60:10: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc: In instantiation of ‘int UnwindImpl(void**, int*, int, int, const void*, int*) [with bool IS_STACK_FRAMES = false; bool IS_WITH_CONTEXT = false]’:
../third_party/abseil-cpp/absl/debugging/stacktrace.cc:124:12:   required from here
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:60:19: error: ‘backtrace’ was not declared in this scope
   60 |   size = backtrace(stack, kStackLength);
      |          ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc: In instantiation of ‘int UnwindImpl(void**, int*, int, int, const void*, int*) [with bool IS_STACK_FRAMES = false; bool IS_WITH_CONTEXT = true]’:
../third_party/abseil-cpp/absl/debugging/stacktrace.cc:126:12:   required from here
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:60:19: error: ‘backtrace’ was not declared in this scope
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc: In instantiation of ‘int UnwindImpl(void**, int*, int, int, const void*, int*) [with bool IS_STACK_FRAMES = true; bool IS_WITH_CONTEXT = false]’:
../third_party/abseil-cpp/absl/debugging/stacktrace.cc:130:12:   required from here
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:60:19: error: ‘backtrace’ was not declared in this scope
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc: In instantiation of ‘int UnwindImpl(void**, int*, int, int, const void*, int*) [with bool IS_STACK_FRAMES = true; bool IS_WITH_CONTEXT = true]’:
../third_party/abseil-cpp/absl/debugging/stacktrace.cc:132:12:   required from here
../third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc:60:19: error: ‘backtrace’ was not declared in this scope
bblanchon commented 6 months ago

__BEGIN_DECLS is defined in sys/cdefs.h as follows:

/* C++ needs to know that types and declarations are C, not C++.  */
#ifdef  __cplusplus
# define __BEGIN_DECLS  extern "C" {
# define __END_DECLS    }
#else
# define __BEGIN_DECLS
# define __END_DECLS
#endif

I tried to add #include <sys/cdefs.h> in execinfo.h, but the compiler doesn't find the header.

jerbob92 commented 6 months ago

My patch was to fix the build for arm64 v8, not for normal arm, that still has other issues as you discovered.

bblanchon commented 6 months ago

🤦 Sorry. Let me try the V8 build.

bblanchon commented 6 months ago

I'm getting the following errors at the very last step:

FAILED: libpdfium.so libpdfium.so.TOC 
"python3" "../build/toolchain/gcc_solink_wrapper.py" --readelf="aarch64-linux-musl-readelf" --nm="aarch64-linux-musl-nm"  --sofile="./libpdfium.so" --tocfile="./libpdfium.so.TOC" --output="./libpdfium.so" -- aarch64-linux-musl-g++ -shared -Wl,-soname="libpdfium.so" -Wl,--fatal-warnings -Wl,--build-id -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fuse-ld=gold -Wl,--threads -Wl,--thread-count=4 -Wl,--icf=all -Wl,-O2 -Wl,--gc-sections -rdynamic -Wl,-z,defs -Wl,--as-needed --sysroot=../build/linux/debian_bullseye_arm64-sysroot -static-libgcc -static-libstdc++ -o "./libpdfium.so" @"./libpdfium.so.rsp"  
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_InterpreterEnterAtBytecode'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_InterpreterEnterAtBytecode'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_InterpreterEnterAtNextBytecode'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_InterpreterEnterAtNextBytecode'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_ContinueToCodeStubBuiltinWithResult'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_ContinueToCodeStubBuiltinWithResult'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_ContinueToCodeStubBuiltin'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_ContinueToCodeStubBuiltin'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_ContinueToJavaScriptBuiltinWithResult'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_ContinueToJavaScriptBuiltinWithResult'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_ContinueToJavaScriptBuiltin'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_ContinueToJavaScriptBuiltin'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'construct_stub_create_deopt_addr'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'construct_stub_create_deopt_addr'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'construct_stub_invoke_deopt_addr'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'construct_stub_invoke_deopt_addr'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_BaselineOrInterpreterEnterAtBytecode'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_BaselineOrInterpreterEnterAtBytecode'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_BaselineOrInterpreterEnterAtNextBytecode'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_BaselineOrInterpreterEnterAtNextBytecode'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_RestartFrameTrampoline'
obj/v8/v8_snapshot/deoptimizer-cfi-builtins.o:deoptimizer-cfi-builtins.cc:function v8::internal::Deoptimizer::IsValidReturnAddress(unsigned long, v8::internal::Isolate*): error: undefined reference to 'Builtins_RestartFrameTrampoline'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

This was with v8_snapshot_toolchain = "//build/toolchain/linux:x64"

jerbob92 commented 6 months ago

What are you building exactly? The main branch?

bblanchon commented 6 months ago

Nevermind, build passed with v8_snapshot_toolchain = "//build/toolchain/linux:clang_x64_v8_arm64"

jerbob92 commented 6 months ago

I think that is what this fixes: https://github.com/bblanchon/pdfium-binaries/pull/133#issuecomment-1758213036

bblanchon commented 6 months ago

Unfortunately, the branch chromium/6110 is 8 commits behind main and doesn't include the V8 patch, so we'll have to wait for next week.