#8561 closed bug (fixed)

Clang/iOS: __builtin___clear_cache doesn't exist in clang, use __clear_cache instead

Reported by: lukexi Owned by:
Priority: high Milestone:
Component: Compiler Version: 7.6.3
Keywords: Cc: thoughtpolice, nkpart@…
Operating System: Other Architecture: Unknown/Multiple
Type of failure: Building GHC failed Test Case:
Blocked By: Blocking:
Related Tickets: #8562 Differential Revisions:

Description

The builtin_clear_cache from GCC is just called clear_cache with clang, and must be declared. Otherwise the build fails

(introduced in https://github.com/ghc/ghc/commit/5bab1a57f572e29dfdffd6d1ce8e53a2772b18fd)

Attachments (2)

clear_cache_support_for_clang.patch (1.5 KB) - added by lukexi 21 months ago.
clear_cache_support_for_clang_via_sys_icache_invalidate.patch (1.7 KB) - added by lukexi 21 months ago.

Download all attachments as: .zip

Change History (16)

Changed 21 months ago by lukexi

comment:1 Changed 21 months ago by lukexi

Actually, __clear_cache seems to be missing entirely on iOS, so I'm not sure what to do here.

(I found a reference to someone reimplementing it in assembly? http://permalink.gmane.org/gmane.comp.lang.pcre.devel/1986)

Last edited 21 months ago by lukexi (previous) (diff)

comment:2 Changed 21 months ago by thoughtpolice

A few years ago I helped Mike Pall (of LuaJIT) dig into using the JIT component on iOS, which involved finding a way to clear the icache.

I dug up the code. On Darwin, the trick seems to be sys_icache_invalidate:

http://repo.or.cz/w/luajit-2.0.git/blob/HEAD:/src/lj_mcode.c#l31

I imagine this still works, but I can't test it (I no longer have a jailbroken iOS device where the JIT would work.)

comment:3 Changed 21 months ago by lukexi

OK, thanks for that! I'm running a build now with

#if defined(ios_HOST_OS) || defined (darwin_HOST_OS)
void sys_icache_invalidate(void *start, size_t len);
#endif

/* Synchronize data/instruction cache. */
void clearCache(void *start, void *end)
{
#if defined(ios_HOST_OS) || defined (darwin_HOST_OS)
  sys_icache_invalidate(start, (char *)end-(char *)start);
#elif defined(__GNUC__)
  __builtin___clear_cache(start, end);
#else
#error "Missing builtin to flush instruction cache"
#endif

adapted from that to test

comment:4 Changed 21 months ago by carter

heatsink is likely to follow up on this, but GCC 4.2 lacks the builtin clear cache primitive, and thus any OS X system with XCode < 5 has a GCC old enough that builtin_clear_cache shoudn't be used.

(at least if we want to support working at all on older OS X systems, which i think is worth doing)

comment:5 Changed 21 months ago by carter

that is, on x86 architectures we perhaps shouldn't be calling clear cache at all.

comment:6 Changed 21 months ago by heatsink

comment:7 Changed 21 months ago by nkpart

  • Cc nkpart@… added

comment:8 Changed 21 months ago by lukexi

(just the above in patch form, it's been working quite happily in intense use on iOS)

comment:9 Changed 21 months ago by amosrobinson

Thanks! I'm trying now on OSX10.8.5 & GCC 4.2.1. I got a warning (and error due to -Werror) that clearCache didn't have a prototype before it, so I made it static.

comment:10 Changed 21 months ago by lukexi

Thanks! updated.

comment:11 Changed 21 months ago by carter

i'm meh about that fixup patch, the real issue is we don't need to call any cache synchronization on x86/ x86_64 architectures.

I'll integrate the above patch into my fixup.

comment:12 Changed 20 months ago by Austin Seipp <austin@…>

In 9fbb8c788d4bdf091709778b42a1294bbdabef95/ghc:

Rejigger flushExec implementation (#8562, #8561)

Instead, just don't do anything on x86/amd64, and on !x86, use either A)
__clear_cache from libgcc, or B) sys_icache_invalidate for OS X (and
iOS.)

Signed-off-by: Austin Seipp <[email protected]>

comment:13 Changed 20 months ago by thoughtpolice

This should now be fixed.

comment:14 Changed 20 months ago by thoughtpolice

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.