Bug 201183 - devel/boehm-gc lacks AARCH64 support (causes www/w3m build failure)
Summary: devel/boehm-gc lacks AARCH64 support (causes www/w3m build failure)
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: arm64 Any
: --- Affects Some People
Assignee: Brad Davis
URL: http://tasty.ysv.freebsd.org/data/11a...
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-28 20:09 UTC by Sean Bruno
Modified: 2015-07-09 14:19 UTC (History)
5 users (show)

See Also:
bugzilla: maintainer-feedback? (nobutaka)


Attachments
boehm-gc-7.4.2_4.diff (3.73 KB, patch)
2015-06-29 20:03 UTC, Carlos J Puga Medina
no flags Details | Diff
patch-include_private_gcconfig.h (2.10 KB, patch)
2015-07-03 18:07 UTC, Carlos J Puga Medina
no flags Details | Diff
boehm-gc build log on AArch64 (47.56 KB, text/x-log)
2015-07-03 18:08 UTC, Carlos J Puga Medina
no flags Details
attempt to build w3m on AArch64 (57.01 KB, text/x-log)
2015-07-03 18:10 UTC, Carlos J Puga Medina
no flags Details
Fix for upstream git (2.37 KB, patch)
2015-07-05 20:10 UTC, Andrew Turner
no flags Details | Diff
boehm-gc-7.4.2_4.diff (6.16 KB, patch)
2015-07-06 19:54 UTC, Carlos J Puga Medina
no flags Details | Diff
boehm-gc-7.4.2_4.diff (7.21 KB, patch)
2015-07-06 22:57 UTC, Carlos J Puga Medina
no flags Details | Diff
boehm-gc-7.4.2_4.diff (7.32 KB, patch)
2015-07-07 00:28 UTC, Carlos J Puga Medina
no flags Details | Diff
boehm-gc tests log (55.17 KB, text/x-log)
2015-07-07 00:35 UTC, Carlos J Puga Medina
no flags Details
11aarch64-default.log (62.60 KB, text/x-log)
2015-07-07 01:33 UTC, Carlos J Puga Medina
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sean Bruno freebsd_committer freebsd_triage 2015-06-28 20:09:31 UTC
There may be a linking/build issue in libgc, but I'm not sure.

| #ifdef __cplusplus
| extern "C"
| #endif
| char GC_init ();
| int
| main ()
| {
| return GC_init ();
|   ;
|   return 0;
| }
configure:8240: result: no
configure:8247: checking GC library location
configure:8249: result: /usr/local
configure:8255: checking /usr/local
configure:8258: checking for GC_init in -lgc
configure:8283: /nxb-bin/usr/bin/cc -o conftest -O2 -pipe  -fno-strict-aliasing -I$(srcdir)/libwc  -I/usr/include/openssl -I/usr/local/include  -I/usr/local/include   -L/usr/local/lib conftest.c -lgc  -lm  >&5
/usr/local/lib/libgc.so: undefined reference to `__stack_base__'
cc: error: linker command failed with exit code 1 (use -v to see invocation)
configure:8283: $? = 1
configure: failed program was:
Comment 1 Sean Bruno freebsd_committer freebsd_triage 2015-06-28 20:14:10 UTC
devel/boehm-gc build log.

http://tasty.ysv.freebsd.org/data/11aarch64-default/2015-06-28_18h00m31s
/logs/boehm-gc-7.4.2_3.log
Comment 2 Andrew Turner freebsd_committer freebsd_triage 2015-06-28 20:51:07 UTC
This is a problem with devel/boehm-gc. In include/private/gcconfig.h there is a list of architectures it supports, and within each a list of supported operating systems. We need to add FreeBSD/arm64 to this list.
Comment 3 Sean Bruno freebsd_committer freebsd_triage 2015-06-28 23:16:47 UTC
(In reply to Andrew Turner from comment #2)
Yeah, was looking at that, but need the maintainer or someone who knows this header file better than I.  A short attempt (at least a pointer to the right locations), looks something like this:

--- gcconfig.h.orig     2014-06-03 06:08:02.000000000 +0000
+++ gcconfig.h  2015-06-28 23:10:15.475514000 +0000
@@ -97,7 +97,7 @@
 # endif
 # if defined(__aarch64__)
 #    define AARCH64
-#    if !defined(LINUX)
+#    if !defined(LINUX) || !defined(FREEBSD)
 #      define NOSYS
 #      define mach_type_known
 #    endif
@@ -402,6 +402,10 @@
 #   define I386
 #   define mach_type_known
 # endif
+# if defined(FREEBSD) && defined(__aarch64__)
+#   define AARCH64
+#   define mach_type_known
+# endif
 # if defined(FREEBSD) && (defined(__amd64__) || defined(__x86_64__))
 #   define X86_64
 #   define mach_type_known
@@ -1998,6 +2022,16 @@
       extern char _end[];
 #     define DATAEND ((ptr_t)(&_end))
 #   endif
+#   ifdef FREEBSD
+#     define OS_TYPE "FREEBSD"
+#     define DYNAMIC_LOADING
+#     define HEURISTIC2
+      extern char etext[];
+      extern int __data_start[];
+#     define DATASTART ((ptr_t)__data_start)
+      extern void *__stack_base__;
+#     define STACKBOTTOM ((ptr_t)__stack_base__)
+#   endif
 #   ifdef NOSYS
       /* __data_start is usually defined in the target linker script.   */
       extern int __data_start[];
Comment 4 Carlos J Puga Medina 2015-06-29 20:03:59 UTC
Created attachment 158170 [details]
boehm-gc-7.4.2_4.diff

Sean,

Your patch was included in the PORTREVISION. Did you experience any problem?
Comment 5 Andrew Turner freebsd_committer freebsd_triage 2015-06-29 20:55:09 UTC
That patch is wrong, FreeBSD doesn't define __stack_base__ for one. I had a look at it, but found issues I need to fix in base before we can get it working.
Comment 6 Carlos J Puga Medina 2015-06-29 21:20:15 UTC
(In reply to Andrew Turner from comment #5)

Yes, it should be as following:

# define FREEBSD_STACKBOTTOM
Comment 7 Carlos J Puga Medina 2015-07-03 18:07:16 UTC
Created attachment 158296 [details]
patch-include_private_gcconfig.h

This patch works for me (add AArch64 support to Boehm GC)

But now I'm stuck at this point:

cc  -I. -I. -O2 -pipe  -fno-strict-aliasing -I./libwc  -I/usr/include/openssl -I/usr/local/include -I/usr/local/include -DHAVE_CONFIG_H -DAUXBIN_DIR=\"/usr/local/libexec/w3m\"  -DCGIBIN_DIR=\"/usr/local/libexec/w3m/cgi-bin\" -DHELP_DIR=\"/usr/local/share/w3m\"  -DETC_DIR=\"/usr/local/etc\" -DCONF_DIR=\"/usr/local/etc/w3m\"  -DRC_DIR=\"~/.w3m\"  -DLOCALEDIR=\"/usr/local/share/locale\" -o mktable mktable.o dummy.o Str.o hash.o myctype.o -L/usr/local/lib -lm -lX11 -lgc
sort funcname.tab | /usr/bin/awk -f ./functable.awk > functable.tab
./mktable 100 functable.tab > functable.c
*** Signal 11

Stop.
make[1]: stopped in /wrkdirs/usr/ports/www/w3m/work/w3m-0.5.3
*** Error code 1
Comment 8 Carlos J Puga Medina 2015-07-03 18:08:31 UTC
Created attachment 158297 [details]
boehm-gc build log on AArch64
Comment 9 Carlos J Puga Medina 2015-07-03 18:10:22 UTC
Created attachment 158298 [details]
attempt to build w3m on AArch64
Comment 10 Carlos J Puga Medina 2015-07-04 11:25:06 UTC
Patch was merged into mainline

https://github.com/ivmai/bdwgc/commit/2282b2013a5a06b8e28225076f4b263d735676f8
Comment 11 Andrew Turner freebsd_committer freebsd_triage 2015-07-04 16:13:14 UTC
The upstream change isn't enough, the tests are all failing:

andrew@arm64:~/bdwgc % ./cordtest
GC Warning: Out of memory - trying to allocate requested amount (8224 bytes)...
Insufficient memory for GC_all_nils
Comment 12 Carlos J Puga Medina 2015-07-04 18:01:16 UTC
(In reply to Andrew Turner from comment #11)

Also we have same problem trying to build www/w3m on MIPS.
Comment 13 Andreas Tobler freebsd_committer freebsd_triage 2015-07-04 18:41:44 UTC
Regarding w3m, powerpc64 is also affected. But it works here if I take the threaded boehm-gc iso the default, non threaded version.
Comment 14 Andrew Turner freebsd_committer freebsd_triage 2015-07-05 20:10:33 UTC
Created attachment 158394 [details]
Fix for upstream git

I've committed all the fixes needed on the FreeBSD side. The attached patch, against Boehm GC from git, gets the arm64 case closer to the other FreeBSD architectures. The tests pass both with and without it.
Comment 15 Carlos J Puga Medina 2015-07-05 22:26:13 UTC
(In reply to Andrew Turner from comment #14)

Did you tried to build w3m port?

It fails at this point:

cc  -I. -I. -O2 -pipe  -fno-strict-aliasing -I./libwc  -I/usr/include/openssl -I/usr/local/include -I/usr/local/include -DHAVE_CONFIG_H -DAUXBIN_DIR=\"/usr/local/libexec/w3m\"  -DCGIBIN_DIR=\"/usr/local/libexec/w3m/cgi-bin\" -DHELP_DIR=\"/usr/local/share/w3m\"  -DETC_DIR=\"/usr/local/etc\" -DCONF_DIR=\"/usr/local/etc/w3m\"  -DRC_DIR=\"~/.w3m\"  -DLOCALEDIR=\"/usr/local/share/locale\" -o mktable mktable.o dummy.o Str.o hash.o myctype.o -L/usr/local/lib -lm -lX11 -lgc
sort funcname.tab | /usr/bin/awk -f ./functable.awk > functable.tab
./mktable 100 functable.tab > functable.c
*** Signal 11
Comment 16 Carlos J Puga Medina 2015-07-06 19:54:26 UTC
Created attachment 158430 [details]
boehm-gc-7.4.2_4.diff

- Add FreeBSD/aarch64 support
- Fix __alloc_size__ availability detection (Clang)
Comment 17 Andrew Turner freebsd_committer freebsd_triage 2015-07-06 20:51:23 UTC
(In reply to Carlos Jacobo Puga Medina from comment #16)

With that patch I can build boehm-gc and w3m on arm64.
Comment 18 Carlos J Puga Medina 2015-07-06 21:14:32 UTC
(In reply to Andrew Turner from comment #17)

Great! 

Patch is ready to be committed.
Comment 19 Carlos J Puga Medina 2015-07-06 22:57:29 UTC
Created attachment 158436 [details]
boehm-gc-7.4.2_4.diff
Comment 20 Carlos J Puga Medina 2015-07-07 00:28:28 UTC
Created attachment 158437 [details]
boehm-gc-7.4.2_4.diff

Patch reworked including fix for undeclared identifier 'BUS_PAGE_FAULT'
Comment 21 Carlos J Puga Medina 2015-07-07 00:35:05 UTC
Created attachment 158438 [details]
boehm-gc tests log
Comment 22 Carlos J Puga Medina 2015-07-07 01:33:34 UTC
Created attachment 158450 [details]
11aarch64-default.log

It passed all tests with CFLAGS=-DNO_INCREMENTAL
Comment 23 Andrew Turner freebsd_committer freebsd_triage 2015-07-08 14:12:16 UTC
I've updated the kernel in base r285268 to correctly pass the code and address of the failing data when userland tries to access invalid memory. This fixes th gctest for me as it was trying to us this data.
Comment 24 Carlos J Puga Medina 2015-07-08 15:24:24 UTC
(In reply to Andrew Turner from comment #23)

Andrew,

The bdwgc issue was reopened to add more fixes for upstream:

https://github.com/ivmai/bdwgc/issues/74

Add what you consider necessary.
Comment 25 commit-hook freebsd_committer freebsd_triage 2015-07-08 20:57:56 UTC
A commit references this bug:

Author: brd
Date: Wed Jul  8 20:57:19 UTC 2015
New revision: 391600
URL: https://svnweb.freebsd.org/changeset/ports/391600

Log:
  Patch devel/boehm-gc to build on AArch64.

  PR:		201183
  Submitted by:	Carlos Jacobo Puga Medina <cpm@fbsd.es>, andrew, sbruno
  Approved by:	bdrewery (mentor)

Changes:
  head/devel/boehm-gc/Makefile
  head/devel/boehm-gc/files/patch-include_gc__config__macros.h
  head/devel/boehm-gc/files/patch-include_private_gc__priv.h
  head/devel/boehm-gc/files/patch-include_private_gcconfig.h
  head/devel/boehm-gc/files/patch-os__dep.c