Opened 9 years ago

Closed 9 years ago

#4999 closed bug (fixed)

build fails on powerpc: error: 'ObjectCode' has no member named 'misalignment'

Reported by: nomeata Owned by: igloo
Priority: high Milestone: 7.2.1
Component: Runtime System Version: 7.0.2
Keywords: Cc: 616635@…, pho@…, mle+hs@…
Operating System: Linux Architecture: powerpc
Type of failure: Building GHC failed Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

When building the Debian package for ghc-7.0.2 on powerpc, the build fails. Build log at https://buildd.debian.org/fetch.cgi?pkg=ghc;ver=7.0.2-1;arch=powerpc;stamp=1299367262 and relevant portion is:

rts/Linker.c:2440:0:
     error: 'ObjectCode' has no member named 'misalignment'

This is the code in question:

static void ocFlushInstructionCache( ObjectCode *oc )
{
    /* The main object code */
    ocFlushInstructionCacheFrom(oc->image + oc->misalignment, oc->fileSize);

    /* Jump Islands */
    ocFlushInstructionCacheFrom(oc->symbol_extras, sizeof(SymbolExtra) * oc->n_symbol_extras);
}

and it is inside

#ifdef powerpc_HOST_ARCH

The misalignment field is defined as

#ifndef USE_MMAP
#ifdef darwin_HOST_OS
                       , int misalignment
#endif
#endif

And USE_MMAP is true if

#if defined(linux_HOST_OS    ) || defined(freebsd_HOST_OS) || \
    defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS ) || \
    defined(openbsd_HOST_OS  ) || \
    ( defined(darwin_HOST_OS ) && !defined(powerpc_HOST_ARCH) ) || \
    defined(kfreebsdgnu_HOST_OS) \
/* Don't use mmap on powerpc-apple-darwin as mmap doesn't support
 * reallocating but we need to allocate jump islands just after each
 * object images. Otherwise relative branches to jump islands can fail
 * due to 24-bits displacement overflow.
 */

(last entry added by Debian, but unrelated to this bug).

It seems that the correct line here should be

    ( !defined(darwin_HOST_OS ) && defined(powerpc_HOST_ARCH) ) || }}}
so that powerpc builds not on darwin use MMAP?

Also, I guess the failing line should be modified to also work in the absence of the misalignment flag.

I’d be grateful if you could tell me what exactly to patch here, as I’m not confident with the inner workings of the rts and even if I get it to compile, I would not be sure that it’s correct.

Thanks,
Joachim

Attachments (3)

powerpc-compile-fix.diff (4.7 KB) - added by erikd 9 years ago.
Patch against 7.0.2 to fix this.
fix-compile-error-on-powerpc_linux-__4999_.2.dpatch (101.2 KB) - added by erikd 9 years ago.
Upadted version of patch. Now compiles but may not be correct.
0001-Fix-compiling-on-linux-powerpc.patch (1.8 KB) - added by erikd 9 years ago.
Minimal patch (against current git head) to fix this particular compile issue.

Download all attachments as: .zip

Change History (20)

comment:1 Changed 9 years ago by PHO

Cc: pho@… added

Hmm... I think we can't use mmap for powerpc builds not only on darwin but on every operation systems, since relative branches with 24-bits displacement should not be darwin specific.

So the correct fix would be to disable mmap and enable oc->misalignment when defined(powerpc_HOST_ARCH).

comment:2 Changed 9 years ago by erikd

It seems like the logic which sets USE_MMAP:

#if defined(linux_HOST_OS    ) || defined(freebsd_HOST_OS) || \
    defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS ) || \
    defined(openbsd_HOST_OS  ) || \
    ( defined(darwin_HOST_OS ) && !defined(powerpc_HOST_ARCH) ) || \
    defined(kfreebsdgnu_HOST_OS) \

should be changed to:

#if !defined(powerpc_HOST_ARCH) && \
    (   defined(linux_HOST_OS    ) || defined(freebsd_HOST_OS) || \
        defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS ) || \
        defined(openbsd_HOST_OS  ) || defined(darwin_HOST_OS ) || \
        defined(kfreebsdgnu_HOST_OS) ) \

so that powerpc_HOST_ARCH is tested regardless of the OS.

comment:3 Changed 9 years ago by erikd

I think I have a fix. Building the Debian package with my fix now. Then I'll test it and then work on a patch against GHC HEAD.

comment:4 Changed 9 years ago by erikd

I have a patch that works (very thoroughly tested) against 7.0.2 which I'll add as an attachment.

I've tried to apply the same patch against GHC HEAD and I've run into this problem:

rts/Linker.c:1073:7:
     error: 'alloc_blocks_lim' undeclared here (not in a function)

rts/Linker.c:1073:7:  warning: missing initializer

rts/Linker.c:1073:7:
     warning: (near initialization for 'rtsSyms[377].addr')

which seems completely unrelated to what I did and has me completely baffled.

Changed 9 years ago by erikd

Attachment: powerpc-compile-fix.diff added

Patch against 7.0.2 to fix this.

comment:5 Changed 9 years ago by simonmar

Your patch has this suspicious hunk:

@@ -981,7 +981,7 @@
       SymI_HasProto(stg_yieldzh)                        \
       SymI_NeedsProto(stg_interp_constr_entry)          \
       SymI_HasProto(stg_arg_bitmaps)                    \
-      SymI_HasProto(large_alloc_lim)                    \
+      SymI_HasProto(alloc_blocks_lim)                   \
       SymI_HasProto(g0)                                 \
       SymI_HasProto(allocate)                           \
       SymI_HasProto(allocateExec)                       \

Removing that should fix the problem.

comment:6 Changed 9 years ago by erikd

Well spotted. Retrying it now.

comment:7 Changed 9 years ago by erikd

Ok, with that bad patch chunk removed, it compiles, with these warnings:

rts/Linker.c:1891:16:
     error: 'misalignment' may be used uninitialized in this function
rts/Linker.c: In function 'loadObj':

rts/Linker.c:2066:7:
     error: 'misalignment' may be used uninitialized in this function

The stage one compile completes, but it errors out in stage 2 when compling the vector library.

Looking at the code in rts/Linker.c, misalignment is caclucaled by a function machoGetMisalignment() which seems to be darwin_HOST_OS specific. We need the powerpc-linux version of that function.

comment:8 Changed 9 years ago by igloo

Milestone: 7.2.1
Owner: set to igloo
Priority: normalhighest

Thanks for the patch!

comment:9 Changed 9 years ago by igloo

Status: newpatch

Changed 9 years ago by erikd

Upadted version of patch. Now compiles but may not be correct.

comment:10 Changed 9 years ago by erikd

I'll attach my latest version of this patch.

With this patch it now compiles, but I'm still not sure its correct. The darwin_HOST_OS code path has a machoGetMisalignment() function call and I'm not sure if there shouldn't be an elfGetMisalignment code path.

With this patch, it now compiles, but validate fails on the second stage compiling the vector library:

Segmentation fault
make[1]: *** [libraries/vector/dist-install/build/Data/Vector/Fusion/Stream/Monadic.o] Error 139

comment:11 Changed 9 years ago by erikd

The function machoGetMisalignment() was added as part of a fix for bug #1845.

comment:12 Changed 9 years ago by igloo

Owner: igloo deleted
Priority: highesthigh
Status: patchnew

OK, I took a look at the patch. It seems to me that a smaller fix for the build problem would be to only add on oc->misalignment in ocFlushInstructionCache on darwin. It may also be necessary to include this part of the patch:

-#if defined(linux_HOST_OS    ) || defined(freebsd_HOST_OS) || \
-    defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS ) || \
-    defined(openbsd_HOST_OS  ) || \
-    ( defined(darwin_HOST_OS ) && !defined(powerpc_HOST_ARCH) ) || \
-    defined(kfreebsdgnu_HOST_OS)
-/* Don't use mmap on powerpc-apple-darwin as mmap doesn't support
+#if !defined(powerpc_HOST_ARCH) && \
+    (   defined(linux_HOST_OS    ) || defined(freebsd_HOST_OS) || \
+        defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS ) || \
+        defined(openbsd_HOST_OS  ) || defined(darwin_HOST_OS ) || \
+        defined(kfreebsdgnu_HOST_OS) )
+/* Don't use mmap on powerpc_HOST_ARCH as mmap doesn't support

I'm not sure if there are any other build problems, and I can't easily test it, so I haven't made the change myself.

The other changes make PPC/Linux use misalignment, but then always set misalignment to 0. I don't know what the deal is with machoGetMisalignment; looking at the current code it looks like it is an OS X thing rather than a PPC thing (e.g. it has a x86_64_HOST_ARCH
powerpc64_HOST_ARCH condition in it).

Changed 9 years ago by erikd

Minimal patch (against current git head) to fix this particular compile issue.

comment:13 Changed 9 years ago by erikd

The patch I just attached (0001-Fix-compiling-on-linux-powerpc.patch) fixes the compile issue in rtc/Linker.c for linux-powerpc.

This patch has also been tested on an x86_64-linux system and I ran the full validate script successfully. Validate couldn't run on powerpc-linux because other bugs exist.

I would like to see this patch applied and this bug closed so I can raise a bug about then other powerpc-linx bug(s).

comment:14 Changed 9 years ago by simonmar

Status: newpatch

comment:15 Changed 9 years ago by erikd

Cc: mle+hs@… added

comment:16 Changed 9 years ago by igloo

Owner: set to igloo

comment:17 Changed 9 years ago by igloo

Resolution: fixed
Status: patchclosed

Applied, thanks!

Note: See TracTickets for help on using tickets.