Skip to content

Commit

Permalink
Issue #1471 - Fix building on sparc64 Linux
Browse files Browse the repository at this point in the history
Correct various pre-processor defines for sparc64 and in mozjemalloc use the JS arm64 allocator on Linux/sparc64.
This corrects build problems opn Linux sparc64 and is in line with bugzilla bug #1275204.
  • Loading branch information
JMadgwick authored and roytam1 committed Apr 3, 2020
1 parent 7f37289 commit 1640ee7
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ipc/chromium/src/build/build_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
#elif defined(__ppc__) || defined(__powerpc__)
#define ARCH_CPU_PPC 1
#define ARCH_CPU_32_BITS 1
#elif defined(__sparc64__)
#elif defined(__sparc__) && defined(__arch64__)
#define ARCH_CPU_SPARC 1
#define ARCH_CPU_64_BITS 1
#elif defined(__sparc__)
Expand Down
6 changes: 3 additions & 3 deletions js/src/gc/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ MapMemoryAt(void* desired, size_t length, int prot = PROT_READ | PROT_WRITE,
// possibly be correct on AMD64, but for Solaris/illumos it is.

{
#if defined(__ia64__) || (defined(__sparc64__) && defined(__NetBSD__)) || defined(__aarch64__) || (defined(__sun) && defined(__x86_64__))
#if defined(__ia64__) || defined(__aarch64__) || (defined(__sun) && defined(__x86_64__)) || (defined(__sparc__) && defined(__arch64__) && (defined(__NetBSD__) || defined(__linux__)))
MOZ_ASSERT((0xffff800000000000ULL & (uintptr_t(desired) + length - 1)) == 0);
#endif
void* region = mmap(desired, length, prot, flags, fd, offset);
Expand All @@ -446,7 +446,7 @@ static inline void*
MapMemory(size_t length, int prot = PROT_READ | PROT_WRITE,
int flags = MAP_PRIVATE | MAP_ANON, int fd = -1, off_t offset = 0)
{
#if defined(__ia64__) || (defined(__sparc64__) && defined(__NetBSD__))
#if defined(__ia64__) || (defined(__sparc__) && defined(__arch64__) && defined(__NetBSD__))
/*
* The JS engine assumes that all allocated pointers have their high 17 bits clear,
* which ia64's mmap doesn't support directly. However, we can emulate it by passing
Expand All @@ -473,7 +473,7 @@ MapMemory(size_t length, int prot = PROT_READ | PROT_WRITE,
return nullptr;
}
return region;
#elif defined(__aarch64__) || (defined(__sun) && defined(__x86_64__))
#elif defined(__aarch64__) || (defined(__sun) && defined(__x86_64__)) || (defined(__sparc__) && defined(__arch64__) && defined(__linux__))
/*
* There might be similar virtual address issue on arm64 which depends on
* hardware and kernel configurations. But the work around is slightly
Expand Down
7 changes: 4 additions & 3 deletions js/src/jsapi-tests/testGCAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ void unmapPages(void* p, size_t size) { }
void*
mapMemoryAt(void* desired, size_t length)
{
#if defined(__ia64__) || (defined(__sparc64__) && defined(__NetBSD__)) || defined(__aarch64__)
#if defined(__ia64__) || defined(__aarch64__) || \
(defined(__sparc__) && defined(__arch64__) && (defined(__NetBSD__) || defined(__linux__)))
MOZ_RELEASE_ASSERT(0xffff800000000000ULL & (uintptr_t(desired) + length - 1) == 0);
#endif
void* region = mmap(desired, length, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
Expand All @@ -324,7 +325,7 @@ mapMemory(size_t length)
int fd = -1;
off_t offset = 0;
// The test code must be aligned with the implementation in gc/Memory.cpp.
#if defined(__ia64__) || (defined(__sparc64__) && defined(__NetBSD__))
#if defined(__ia64__) || (defined(__sparc__) && defined(__arch64__) && defined(__NetBSD__))
void* region = mmap((void*)0x0000070000000000, length, prot, flags, fd, offset);
if (region == MAP_FAILED)
return nullptr;
Expand All @@ -334,7 +335,7 @@ mapMemory(size_t length)
return nullptr;
}
return region;
#elif defined(__aarch64__)
#elif defined(__aarch64__) || (defined(__sparc__) && defined(__arch64__) && defined(__linux__))
const uintptr_t start = UINT64_C(0x0000070000000000);
const uintptr_t end = UINT64_C(0x0000800000000000);
const uintptr_t step = js::gc::ChunkSize;
Expand Down
2 changes: 1 addition & 1 deletion media/webrtc/trunk/build/build_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
#define ARCH_CPU_PPC 1
#define ARCH_CPU_32_BITS 1
#define ARCH_CPU_BIG_ENDIAN 1
#elif defined(__sparc64__)
#elif defined(__sparc__) && defined(__arch64__)
#define ARCH_CPU_SPARC_FAMILY 1
#define ARCH_CPU_SPARC 1
#define ARCH_CPU_64_BITS 1
Expand Down
2 changes: 1 addition & 1 deletion media/webrtc/trunk/webrtc/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#define WEBRTC_ARCH_BIG_ENDIAN
#define WEBRTC_BIG_ENDIAN
#endif
#elif defined(__sparc64__)
#elif defined(__sparc__) && defined(__arch64__)
#define WEBRTC_ARCH_SPARC 1
#define WEBRTC_ARCH_64_BITS 1
#define WEBRTC_ARCH_BIG_ENDIAN
Expand Down
29 changes: 26 additions & 3 deletions memory/mozjemalloc/jemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,7 @@ static void *
pages_map(void *addr, size_t size)
{
void *ret;
#if defined(__ia64__)
#if defined(__ia64__) || (defined(__sparc__) && defined(__arch64__) && defined(__linux__))
/*
* The JS engine assumes that all allocated pointers have their high 17 bits clear,
* which ia64's mmap doesn't support directly. However, we can emulate it by passing
Expand All @@ -1992,6 +1992,28 @@ pages_map(void *addr, size_t size)
}
#endif

#if defined(__sparc__) && defined(__arch64__) && defined(__linux__)
const uintptr_t start = 0x0000070000000000ULL;
const uintptr_t end = 0x0000800000000000ULL;

/* Copied from js/src/gc/Memory.cpp and adapted for this source */

uintptr_t hint;
void* region = MAP_FAILED;
for (hint = start; region == MAP_FAILED && hint + size <= end; hint += chunksize) {
region = mmap((void*)hint, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
if (region != MAP_FAILED) {
if (((size_t) region + (size - 1)) & 0xffff800000000000) {
if (munmap(region, size)) {
MOZ_ASSERT(errno == ENOMEM);
}
region = MAP_FAILED;
}
}
}
ret = region;
#else

/*
* We don't use MAP_FIXED here, because it can cause the *replacement*
* of existing mappings, and we only want to create new mappings.
Expand All @@ -2000,10 +2022,11 @@ pages_map(void *addr, size_t size)
MAP_PRIVATE | MAP_ANON, -1, 0);
assert(ret != NULL);

#endif
if (ret == MAP_FAILED) {
ret = NULL;
}
#if defined(__ia64__)
#if defined(__ia64__) || (defined(__sparc__) && defined(__arch64__) && defined(__linux__))
/*
* If the allocated memory doesn't have its upper 17 bits clear, consider it
* as out of memory.
Expand Down Expand Up @@ -2036,7 +2059,7 @@ pages_map(void *addr, size_t size)
MozTagAnonymousMemory(ret, size, "jemalloc");
}

#if defined(__ia64__)
#if defined(__ia64__) || (defined(__sparc__) && defined(__arch64__) && defined(__linux__))
assert(ret == NULL || (!check_placement && ret != NULL)
|| (check_placement && ret == addr));
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#define GOOGLE_PROTOBUF_ARCH_32_BIT 1
#elif defined(sparc)
#define GOOGLE_PROTOBUF_ARCH_SPARC 1
#ifdef SOLARIS_64BIT_ENABLED
#ifdef __arch64__
#define GOOGLE_PROTOBUF_ARCH_64_BIT 1
#else
#define GOOGLE_PROTOBUF_ARCH_32_BIT 1
Expand Down
4 changes: 2 additions & 2 deletions xpcom/reflect/xptcall/md/unix/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ if CONFIG['OS_ARCH'] == 'OpenBSD' and CONFIG['OS_TEST'] == 'powerpc':
'xptcstubs_ppc_openbsd.cpp',
]

if CONFIG['OS_ARCH'] == 'Linux' and 'sparc' in CONFIG['OS_TEST']:
if CONFIG['OS_ARCH'] == 'Linux' and CONFIG['OS_TEST'] == 'sparc':
SOURCES += [
'xptcinvoke_asm_sparc_linux_GCC3.s',
'xptcinvoke_sparc_solaris.cpp',
Expand Down Expand Up @@ -205,7 +205,7 @@ if CONFIG['OS_ARCH'] == 'OpenBSD' and CONFIG['OS_TEST'] == 'sparc':
# files for 64-bit SPARC with no ill effects, so basically the entire mess that
# was there before is no longer needed.

if CONFIG['OS_ARCH'] in ('OpenBSD', 'FreeBSD', 'SunOS') and CONFIG['OS_TEST'] == 'sparc64':
if CONFIG['OS_ARCH'] in ('OpenBSD', 'FreeBSD', 'SunOS', 'Linux') and CONFIG['OS_TEST'] == 'sparc64':
SOURCES += [
'xptcinvoke_asm_sparc64_openbsd.s',
'xptcinvoke_sparc64_openbsd.cpp',
Expand Down

0 comments on commit 1640ee7

Please sign in to comment.