Created attachment 231075 [details]
Patch configure for armv7 support on FreeBSD
Thanks for your report. Please find attached a patch for the files subdirectory that should allow you to build devel/ocaml-opam on arm. Would you be able to test the patch and report back (since I don't have access to a FreeBSD arm system)?
Thanks a lot.
Created attachment 231080 [details]
devel/ocaml-opam 2.1.2 build log after applying patch #231075
Hi Hannes,
That seems to have not done the trick; the build fails with the same issue. See attached build log for the failure.
Could it be that you need to patch the configure script in the bootstrap directory created during the build?
(In reply to Robert Clausecker from comment #2) Thanks for testing. From your build output: Hmm... Looks like a unified diff to me... The text leading up to this was: -------------------------- |diff --git a/configure b/configure |index b1e287aed..4754e8ab2 100755 |--- a/configure |+++ b/configure -------------------------- Patching file configure using Plan A... Hunk #1 succeeded at 14120. Hmm... The next patch looks like a unified diff to me... The text leading up to this was: -------------------------- |diff --git a/configure.ac b/configure.ac |index 656ffe20c..1c9694805 100644 |--- a/configure.ac |+++ b/configure.ac -------------------------- Patching file configure.ac using Plan A... Hunk #1 succeeded at 1070. done configure: Configuring OCaml version 4.12.1 This only shows a single hunk for each (configure/configure.ac) file -- which is the case for the current devel/ocaml-opam patch (files/patch-src__ext_ocaml_patches_0001-Fix-rela...), while my attachment above had a second hunk in each of the files (with the arm fix). Could you verify that your build actually had my attachment as patch applied? This patch file is used after the ocaml compiler sources are unpacked, but before configure is executed. Thanks a lot! (In reply to Hannes Mehnert from comment #3) on my machine, the start of a make build looks like: Hmm... Looks like a unified diff to me... The text leading up to this was: -------------------------- |diff --git a/configure b/configure |index b1e287aed..4754e8ab2 100755 |--- a/configure |+++ b/configure -------------------------- Patching file configure using Plan A... Hunk #1 succeeded at 13901. Hunk #2 succeeded at 14122. Hmm... The next patch looks like a unified diff to me... The text leading up to this was: -------------------------- |diff --git a/configure.ac b/configure.ac |index 656ffe20c..1c9694805 100644 |--- a/configure.ac |+++ b/configure.ac -------------------------- Patching file configure.ac using Plan A... Hunk #1 succeeded at 971. Hunk #2 succeeded at 1072. done configure: Configuring OCaml version 4.12.1 Notice the 2 hunks for both files. Created attachment 231087 [details] devel/ocaml-opam 2.1.2 build log after applying patch #231075 (In reply to Hannes Mehnert from comment #3) Hi Hannes, I had accidentally uploaded the wrong build log. Here's the right one, showing that your patch took effect. (In reply to Robert Clausecker from comment #5) Thanks for your updated log. In order to fix the issue, I wanted to setup a virtual armv7/FreeBSD system to have faster turnarounds. I tried https://wiki.freebsd.org/QemuRecipes (i.e. using qemu and an FreeBSD 13 installer image), I can see the loader, but no kernel output (I put console=comsonsole in /boot/loader.conf and -Dh in /boot.config) -- instead qemu uses 100% CPU and I see a single "|" (maybe the spinner from the kernel?). Do you have any experience / guidance on how to setup an emulated armv7 system on a FreeBSD/13.0/amd64 host? Of course what you could try on your system is to remove the `model=armv7` from the patch attached in this PR (or set `model=armv6` -- it looks like OCaml on FreeBSD/arm is only support with the armv6), but I'm not sure that'll lead to a working package. (In reply to Hannes Mehnert from comment #6) Hi Hannes, Unfortunately I have no experience with that. I use a Raspberry Pi for ARM testing. It's because the bootstrap tarball is extracted at build time: step to reproduce: modify work/opam-full-2.1.2/bootstrap/ocaml-4.12.1/configure.ac chflags schg work/opam-full-2.1.2/bootstrap/ocaml-4.12.1/configure.ac make cd /usr/ports/devel/ocaml-opam/work/opam-full-2.1.2 && gmake compiler gmake[2]: Entering directory '/usr/ports/devel/ocaml-opam/work/opam-full-2.1.2' env MAKE=gmake BOOTSTRAP_EXTRA_OPTS= BOOTSTRAP_OPT_TARGET=opt.opt BOOTSTRAP_ROOT=.. BOOTSTRAP_DIR=bootstrap ./shell/bootstrap-ocaml.sh ocaml-4.12.1/configure.ac: Can't unlink already-existing object tar: Error exit delayed from previous errors. (In reply to Mikael Urankar from comment #8) nevermind, the patch is applied with shell/bootstrap-ocaml.sh You need to put NOPRECIOUSMAKEVARS=yes in the port Makefile (to not override ARCH in ocaml makefiles) the patch together with NOPRECIOUSMAKEVARS=yes in the port Makefile gave me a successful build on arm64 (NanoPi R4S). after more testing on arm.armv7 and arm64.aarch64 it seems that while the attached patch is not sufficient to fix the build it is a step in the right direction. 1. unmodified devel/ocaml-opam: 1.1 arm64.aarch64 FreeBSD 13 fails: gmake[5]: *** No rule to make target 'aarch64.o', needed by 'libasmrun.a'. 1.2 arm.armv7 FreeBSD 13 fails: gmake[5]: *** No rule to make target 'armv7.o', needed by 'libasmrun.a'. 2. with NOPRECIOUSMAKEVARS=yes in Makefile 2.1 arm64.aarch64 FreeBSD 13 succeeds 2.2 arm.armv7 FreeBSD 13 fails: Makefile:920: *** The native-code compiler is not supported on this platform. 3. with NOPRECIOUSMAKEVARS=yes in Makefile and applied patch 3.1 arm64.aarch64 FreeBSD 13 succeeds 3.2 arm.armv7 FreeBSD 13 fails: ld: error: can't create dynamic relocation R_ARM_ABS32 against symbol: caml_program in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output >>> defined in arm_libasmrunpic.o >>> referenced by arm_libasmrunpic.o:(.text+0x1D0) ld: error: can't create dynamic relocation R_ARM_ABS32 against symbol: Caml_state in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output >>> defined in domain.npic.o >>> referenced by arm_libasmrunpic.o:(.text+0x1D4) ld: error: can't create dynamic relocation R_ARM_ABS32 against local symbol in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output >>> defined in arm_libasmrunpic.o >>> referenced by arm_libasmrunpic.o:(.text+0x1D8) ld: error: can't create dynamic relocation R_ARM_ABS32 against symbol: caml_apply2 in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output >>> defined in arm_libasmrunpic.o >>> referenced by arm_libasmrunpic.o:(.text+0x1DC) ld: error: can't create dynamic relocation R_ARM_ABS32 against symbol: caml_apply3 in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output >>> defined in arm_libasmrunpic.o >>> referenced by arm_libasmrunpic.o:(.text+0x1E0) ld: error: can't create dynamic relocation R_ARM_ABS32 against symbol: caml_array_bound_error in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output >>> defined in fail_nat.npic.o >>> referenced by arm_libasmrunpic.o:(.text+0x1E4) cc: error: linker command failed with exit code 1 (use -v to see invocation) gmake[5]: *** [Makefile:311: libasmrun_shared.so] Error 1 (In reply to Stefan Grundmann from comment #12) Thanks for your experiments! This is very valuable. I'll look into possibly patching the linker errors you posted. -z notext is not the right solution usually. Created attachment 232043 [details]
File oatch-src__ext_ocaml-patches_0001-Fix-relocation-ocaml-32-bit.patch
Could you test this patch instead of the one posted earlier? This should also avoid the ld warning on arm.
Created attachment 232044 [details]
Patch for devel/ocaml-opam/Makefile
Thanks for testing. I uploaded a patch to replace the files/patch-src__ext_ocaml-patches_0001-Fix-relocation-ocaml-32-bit.patch and a patch for the Makefile. With both applied, does a build work on arm32? > -z notext is not the right solution usually There's a discussion in https://github.com/ocaml/ocaml/pull/10835 -- indeed there could be a nicer way (see https://github.com/ocaml/ocaml/pull/10835#issuecomment-1011266122 - with a (partial?) patch to avoid the issue on arm), but the attached patch may be sufficient and doesn't need to modify the assembly. arm.armv7 with patch from 2022-02-23 14:08 UTC and NOPRECIOUSMAKEVARS= yes in Makefile fails: gmake[6]: Entering directory '/usr/ports/devel/ocaml-opam/work/opam-full-2.1.2/bootstrap/ocaml-4.12.1/stdlib' ../boot/ocamlrun ../ocamlopt -strict-sequence -absname -w +a-4-9-41-42-44-45-48 -g -warn-error A -bin-annot -nostdlib -principal -safe-string -strict-formats -nopervasives -c camlinternalFormatBasics.ml /tmp/camlasmccb845.s:58:1: error: symbol '.L116' is already defined .L116: ^ /tmp/camlasmccb845.s:459:1: error: symbol '.L193' is already defined .L193: ^ /tmp/camlasmccb845.s:861:1: error: symbol '.L280' is already defined .L280: ^ File "/usr/ports/devel/ocaml-opam/work/opam-full-2.1.2/bootstrap/ocaml-4.12.1/stdlib/camlinternalFormatBasics.ml", line 1: Error: Assembler error, input left in file /tmp/camlasmccb845.s Created attachment 248241 [details]
0001-devel-ocaml-opam-Fix-build-on-armv7.patch
Created attachment 248242 [details]
0002-devel-ocaml-opam-GNUMake-run-dependency.patch
Hello, Please consider applying the newly attached patches. The first one, 0001-devel-ocaml-opam-Fix-build-on-armv7.patch fixes this ticket. The text relocations issue is fixed by supplying LDFLAGS to the configure (hence no need to patch the OCaml configure script), and the later assembler issue reported by Stefan. (In reply to Stefan Grundmann from comment #17) It seems that ocaml generated assembly for ARM 32 contains duplicated (identical) sections, which GNU binutils happily processes. Fixed by setting USE_BINUTILS on ARM32 archs. This patch is likley to fix armv6 and ppc32 as well. The second patch, 0002-devel-ocaml-opam-GNUMake-run-dependency.patch adds gmake as run dep, as it is required for opam init to bootstrap an OCaml compiler. IOW it is required in most of the user use-cases, except for opam-install as part of some other (package). Comment on attachment 248241 [details]
0001-devel-ocaml-opam-Fix-build-on-armv7.patch
Request maintainer approval.
Comment on attachment 248242 [details]
0002-devel-ocaml-opam-GNUMake-run-dependency.patch
Request maintainer approval.
Are there patches 3--6 or is it only these two?
(In reply to Robert Clausecker from comment #22) Ah sorry this is only those two patches indeed. They were were sitting at the bottom of my patch queue which contains a gigantic, tree-wide, OCaml update (that I'll try to submit later once it gets more polished, but first thing first...). Note that the previous 2 patches were validated on CURRENT and on armv7, i386 and amd64 using poudriere. Aarch64 is likely ok as well, however poudriere is still busy chewing the head of the queue at this time... :) The 0001-devel-ocaml-opam-Fix-build-on-armv7.patch patch has been tested on CURRENT/arm64 as well. (In reply to Benjamin Jacobs from comment #23) Thanks for your patches and testing. I confirm that they're fine (though, due to lack of hardware, I haven't tested them on arm32 architectures -- but I trust your poudriere results). Again, thanks a lot! The USE_BINUTILS part won't work as ARCH is only set when bsd.port.mk is included. I'll go ahead and change this slightly so it works. Ok nice catch, and I'm sorry, I guess that I've must added the if after testing on armv7 in my testing cycle :-/ It sure works with USE_BINUTILS=yes on all the other arch too, but it isn't really needed so I added the if later. While at it, maybe you could add a RUN_DEPENDS_${ARCH} to RUN_DEPENDS and a pair or of RUN_DEPENDS_armv6/RUN_DEPENDS_armv7=${LOCALBASE}/bin/as:devel/binutils, as this will make sure that an "opam switch create xwz" has a reasonable chance to work too? Thanks to both of you, and I'm looking forward to see this bug resolved :) Created attachment 248259 [details]
0001-devel-ocaml-opam-Fix-build-on-armv7.patch
Created attachment 248260 [details]
0002-devel-ocaml-opam-GNUMake-run-dependency.patch
Created attachment 248261 [details]
0001-devel-ocaml-opam-Fix-build-on-armv7.patch
Created attachment 248262 [details]
0002-devel-ocaml-opam-GNUMake-run-dependency.patch
Hi again, I've updated the patches. I'll confirm once my armv7 is done building. (In reply to Benjamin Jacobs from comment #32) Thanks for your updated patches. I tried (and failed) to set the flag maintainer-approval to true. I hereby approve the most recent two patches. Thanks a lot for your work on this! (In reply to Hannes Mehnert from comment #33) Cool! In the mean time, I can confirm that those patches produce a working package. Tested on a cubieboard v1: opam was succesfully able to bootstrap an ocaml compiler from the official Opam repository. # opam init && opam switch create 5.1.0 && eval `opam env`; which ocamlc.opt /root/.opam/5.1.0/bin/ocamlc.opt # ocamlc.opt -config |grep -e model -e arch architecture: arm model: armv7 A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=173b2c2ac99f5372e18feb94d81453d56ba93c67 commit 173b2c2ac99f5372e18feb94d81453d56ba93c67 Author: Benjamin Jacobs <freebsd@dev.thsi.be> AuthorDate: 2024-02-07 18:42:30 +0000 Commit: Robert Clausecker <fuz@FreeBSD.org> CommitDate: 2024-02-10 13:42:58 +0000 devel/ocaml-opam: GNUMake run dependency. GNUMake is needed to build ocaml, and therefore it is needed by the `opam init` command. PR: 261180 Reported by: fuz Approved by: hannes@mehnert.org (maintainer) MFH: 2024Q1 devel/ocaml-opam/Makefile | 1 + 1 file changed, 1 insertion(+) A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=84ef6c1c612525c29dd4c271ea4e91c2d54074af commit 84ef6c1c612525c29dd4c271ea4e91c2d54074af Author: Benjamin Jacobs <freebsd@dev.thsi.be> AuthorDate: 2024-02-07 18:10:46 +0000 Commit: Robert Clausecker <fuz@FreeBSD.org> CommitDate: 2024-02-10 13:42:26 +0000 devel/ocaml-opam: Fix build on armv7. The LLVM assembler chokes on the assembly generated by the ARM32 backend of OCAML. Fixed by forcing binutils on ARM32. The OCaml compiler generates text relocations on all of its supported 32 bits architectures, however the configure script only sets the -z notext linker flag in the x86 case. This change makes sure that this flag is used for the other architectures by setting LDFLAGS in the environment of the configure script. This commit may fix armv6 and powerpc as well, but this hasn't been verified. PR: 261180 MFH: 2024Q1 Reported by: fuz Approved by: hannes@mehnert.org (maintainer) devel/ocaml-opam/Makefile | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) A commit in branch 2024Q1 references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=e8511dc888403b210b509c00f0b3f8e9c081d81a commit e8511dc888403b210b509c00f0b3f8e9c081d81a Author: Benjamin Jacobs <freebsd@dev.thsi.be> AuthorDate: 2024-02-07 18:10:46 +0000 Commit: Robert Clausecker <fuz@FreeBSD.org> CommitDate: 2024-02-10 13:49:20 +0000 devel/ocaml-opam: Fix build on armv7. The LLVM assembler chokes on the assembly generated by the ARM32 backend of OCAML. Fixed by forcing binutils on ARM32. The OCaml compiler generates text relocations on all of its supported 32 bits architectures, however the configure script only sets the -z notext linker flag in the x86 case. This change makes sure that this flag is used for the other architectures by setting LDFLAGS in the environment of the configure script. This commit may fix armv6 and powerpc as well, but this hasn't been verified. PR: 261180 MFH: 2024Q1 Reported by: fuz Approved by: hannes@mehnert.org (maintainer) (cherry picked from commit 84ef6c1c612525c29dd4c271ea4e91c2d54074af) devel/ocaml-opam/Makefile | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) A commit in branch 2024Q1 references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=bc1d478dce2b37067d9834f92bfe97e296b1503a commit bc1d478dce2b37067d9834f92bfe97e296b1503a Author: Benjamin Jacobs <freebsd@dev.thsi.be> AuthorDate: 2024-02-07 18:42:30 +0000 Commit: Robert Clausecker <fuz@FreeBSD.org> CommitDate: 2024-02-10 13:49:20 +0000 devel/ocaml-opam: GNUMake run dependency. GNUMake is needed to build ocaml, and therefore it is needed by the `opam init` command. PR: 261180 Reported by: fuz Approved by: hannes@mehnert.org (maintainer) MFH: 2024Q1 (cherry picked from commit 173b2c2ac99f5372e18feb94d81453d56ba93c67) devel/ocaml-opam/Makefile | 1 + 1 file changed, 1 insertion(+) Thank you for the patches! Committed them with minor changes. Thank you Robert! (In reply to Benjamin Jacobs from comment #40) Thanks Robert and Benjamin. |
Created attachment 230990 [details] devel/ocaml-opam 2.1.2 build log on armv7 FreeBSD 13. An attempt to build this package in version 2.1.2 on armv7 FreeBSD 13 from branch 2022Q1 fails because an object file armv7.o cannot be built. gmake[4]: *** No rule to make target 'armv7.o', needed by 'libasmrun.a'. This is likely because the architecture is detected as armv7 when it should be arm. A source file arm.S exists and I suppose patching the configure script to set the architecture to arm even when armv6 or armv7 is detected might fix the build. See attached build log for details.