Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#1979: steps towards building on MacOS 64-bit #2269

Merged
merged 3 commits into from
Mar 8, 2017

Conversation

shawndenbow
Copy link
Contributor

This commit gets core DR building on MacOS 64-bit.
+ change error notifications to warning to allow build to continue
+ define SC_FIELD for 64-bit registers r8-r15 and update references
+ update dynamorio_mach_dep_syscall to use syscall for 64-bit
+ update dynamorio_mach_syscall to use syscall for 64-bit
+ change code referencing eflags to xflags for cross platform compat
+ misc code fix-ups

    This commit gets core DR building on MacOS 64-bit.
    + change error notifications to warning to allow build to continue
    + define SC_FIELD for 64-bit registers r8-r15 and update references
    + update dynamorio_mach_dep_syscall to use syscall for 64-bit
    + update dynamorio_mach_syscall to use syscall for 64-bit
    + change code referencing eflags to xflags for cross platform compat
    + misc code fix-ups
Copy link
Contributor

@derekbruening derekbruening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the TLS read change needs to read a 64-bit value

# ifdef X64
mov REG_XAX, QWORD [REG_XAX] /* load mach_synch_t->sem */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can stay where it was, shared between the two, via s/DWORD/PTRSZ/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's convenient. Done.

@@ -42,6 +42,9 @@

#include "../asm_defines.asm"
#include "x86_asm_defines.asm" /* PUSHGPR, POPGPR, etc. */
#ifdef MACOS
# include <include/syscall_mach.h> /* SYSCALL_NUM_MARKER_MACH */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"" rather than <> as this is our include, not from /usr/include

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

core/unix/os.c Outdated
ASSERT(is_thread_tls_initialized());
DOCHECK(1, {
thread_id_t old_tid;
int32_t old_tid; /* can't use thread_id_t since it's 64-bits on x64 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait -- os_local_state_t.tid is thread_id_t though, so we need to read a pointer-sized value via READ_TLS_SLOT_IMM, rather than changing these locals to ints. Maybe have a READ_TLS_TIDSZ_SLOT_IMM or sthg.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Ok, for this case I think using a pointer-sized w/ READ_TLS_SLOT_IMM works. That's mentioned in the comments too where the macro is defined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you'll read too much for Linux: pid_t is 32 bits even for x86_64. Do you mean you'll read extra into a local and then truncate it (and assume little-endian)?

@@ -2794,11 +2794,9 @@ fixup_rtframe_pointers(dcontext_t *dcontext, int sig,
# endif
/* 32-bit kernel copies to aligned buf first */
IF_X64(ASSERT(ALIGNED(f_new->uc.uc_mcontext.fpstate, 16)));
#elif defined(MACOS)
# ifndef X64
#elif defined(MACOS) && !defined(X64) /* XXX: macos 64-bit support needs work */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should X64 have an ASSERT_NOT_IMPLEMENTED?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -2964,7 +2962,7 @@ copy_frame_to_stack(dcontext_t *dcontext, int sig, sigframe_rt_t *frame, byte *s
}
#endif /* X86 && LINUX */

#ifdef MACOS
#if defined(MACOS) && !defined(X64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should X64 have an ASSERT_NOT_IMPLEMENTED?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

core/unix/os.c Outdated
ASSERT(old_tid == old);
});
WRITE_TLS_INT_SLOT_IMM(TLS_THREAD_ID_OFFSET, new_tid);
WRITE_TLS_SLOT_IMM(TLS_THREAD_ID_OFFSET, new_tid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will overflow for Linux x64 where pid_t (== thread_id_t) is 32 bits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

core/unix/os.c Outdated
int32_t old_tid; /* can't use thread_id_t since it's 64-bits on x64 */
READ_TLS_INT_SLOT_IMM(TLS_THREAD_ID_OFFSET, old_tid);
ptr_int_t old_tid;
READ_TLS_SLOT_IMM(TLS_THREAD_ID_OFFSET, old_tid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will read the adjacent field (or maybe padding, did not check the struct): it would have to be truncated (or have a custom READ_TLS_SLOT_TIDSZ_IMM as suggested in original comment, or have series of ifdefs or sizeof checks here).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok...I wasn't thinking on this one. Done.

@shawndenbow shawndenbow merged commit 4975170 into project-mac64 Mar 8, 2017
@shawndenbow shawndenbow deleted the i58-mac64-build branch March 8, 2017 23:26
derekbruening added a commit that referenced this pull request Apr 15, 2019
A series of small changes to build with XCode 10.1 64-bit:
+ Updates -max_supported_os_version on Mac to 18.
+ Updates 64-bit Mac frame field.
+ Removes , from runtime options in template defines.
+ Removes 32-bit-only tests from the OSX label list for 64-bit.
+ Increases the core's preferred base to 0x1'71000000 to stay above
  the default 0x1' _PAGEZERO.
+ Adds missing DECL_EXTERNs in mangle_suspend and mangle_asynch tests.
+ Adds missing GLOBAL_REFs in common.decode test.
+ Re-defines sigcontext_t and uc_mcontext in tools.h to match this toolchain.
+ Adds 64-bit libelftc.a and libdwarf.a Mach-O libraries along with
  instructions on how they were built.
+ Adds -mmacosx-version-min=10.9 to drcachesim to match core/.
+ Fixes a format string warning in drcachesim.

Includes a number of similar small changes from Shawn Denbow's first 2
commits on the project-mac64 branch in PR #2269 and PR #2273, updated for
clang-format:
+ Move -vm_base above 4GB since __PAGEZERO takes up first 4GB by default
+ Increase MEMQUERY_INTERNAL_DATA_LEN
+ Update Mach-O parsing to check for LC_SEGMENT_64
+ Change error notifications to warning to allow build to continue
+ Define SC_FIELD for 64-bit registers r8-r15 and update references
+ Update dynamorio_mach_dep_syscall to use syscall for 64-bit
+ Update dynamorio_mach_syscall to use syscall for 64-bit
+ Change code referencing eflags to xflags for cross platform compat
+ Misc code fix-ups

Issue: #1979
derekbruening added a commit that referenced this pull request Apr 15, 2019
A series of small changes to build with XCode 10.1 64-bit (from PR #3514 on project-mac64):
+ Updates -max_supported_os_version on Mac to 18.
+ Updates 64-bit Mac frame field.
+ Removes , from runtime options in template defines.
+ Removes 32-bit-only tests from the OSX label list for 64-bit.
+ Increases the core's preferred base to 0x1'71000000 to stay above
  the default 0x1' _PAGEZERO.
+ Adds missing DECL_EXTERNs in mangle_suspend and mangle_asynch tests.
+ Adds missing GLOBAL_REFs in common.decode test.
+ Re-defines sigcontext_t and uc_mcontext in tools.h to match this toolchain.
+ Adds 64-bit libelftc.a and libdwarf.a Mach-O libraries along with
  instructions on how they were built.
+ Adds -mmacosx-version-min=10.9 to drcachesim to match core/.
+ Fixes a format string warning in drcachesim.

Includes a number of similar small changes from Shawn Denbow's first 2
commits on the project-mac64 branch in PR #2269 and PR #2273, updated for
clang-format:
+ Move -vm_base above 4GB since __PAGEZERO takes up first 4GB by default
+ Increase MEMQUERY_INTERNAL_DATA_LEN
+ Update Mach-O parsing to check for LC_SEGMENT_64
+ Change error notifications to warning to allow build to continue
+ Define SC_FIELD for 64-bit registers r8-r15 and update references
+ Update dynamorio_mach_dep_syscall to use syscall for 64-bit
+ Update dynamorio_mach_syscall to use syscall for 64-bit
+ Change code referencing eflags to xflags for cross platform compat
+ Misc code fix-ups

Issue: #1979
hgreving2304 pushed a commit that referenced this pull request Apr 22, 2019
A series of small changes to build with XCode 10.1 64-bit (from PR #3514 on project-mac64):
+ Updates -max_supported_os_version on Mac to 18.
+ Updates 64-bit Mac frame field.
+ Removes , from runtime options in template defines.
+ Removes 32-bit-only tests from the OSX label list for 64-bit.
+ Increases the core's preferred base to 0x1'71000000 to stay above
  the default 0x1' _PAGEZERO.
+ Adds missing DECL_EXTERNs in mangle_suspend and mangle_asynch tests.
+ Adds missing GLOBAL_REFs in common.decode test.
+ Re-defines sigcontext_t and uc_mcontext in tools.h to match this toolchain.
+ Adds 64-bit libelftc.a and libdwarf.a Mach-O libraries along with
  instructions on how they were built.
+ Adds -mmacosx-version-min=10.9 to drcachesim to match core/.
+ Fixes a format string warning in drcachesim.

Includes a number of similar small changes from Shawn Denbow's first 2
commits on the project-mac64 branch in PR #2269 and PR #2273, updated for
clang-format:
+ Move -vm_base above 4GB since __PAGEZERO takes up first 4GB by default
+ Increase MEMQUERY_INTERNAL_DATA_LEN
+ Update Mach-O parsing to check for LC_SEGMENT_64
+ Change error notifications to warning to allow build to continue
+ Define SC_FIELD for 64-bit registers r8-r15 and update references
+ Update dynamorio_mach_dep_syscall to use syscall for 64-bit
+ Update dynamorio_mach_syscall to use syscall for 64-bit
+ Change code referencing eflags to xflags for cross platform compat
+ Misc code fix-ups

Issue: #1979
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants