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

Build failed: build zydis as a dynamic link library on MacOS #474

Closed
JamesAldridge opened this issue Jan 16, 2024 · 4 comments · Fixed by #475
Closed

Build failed: build zydis as a dynamic link library on MacOS #474

JamesAldridge opened this issue Jan 16, 2024 · 4 comments · Fixed by #475
Labels
A-build Area: Build system

Comments

@JamesAldridge
Copy link

Seems to be the same issue as #350

System Specifications:

Operating System: macOS Sonoma 14.1 (23B74)
CPU: 2.7 GHz Quad-Core Intel Core i7
Compiler Info:
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: x86_64-apple-darwin23.1.0
Thread model: posix

When i build zydis with shared flag, the problem I've encountered is as follows.

Jamess-MacBook-Pro-4:jak-project-v-update-zydis jamesaldridge$ cmake --build build --parallel $((sysctl -n hw.logicalcpu`))
[0/2] Re-checking globbed directories...
[2/11] Linking C shared library third-party/zydis/libZydis.4.0.0.0.dylib
FAILED: third-party/zydis/libZydis.4.0.0.0.dylib
: && /usr/bin/clang -O3 -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk -dynamiclib -Wl,-headerpad_max_install_names -compatibility_version 4.0.0 -current_version 4.0.0 -o third-party/zydis/libZydis.4.0.0.0.dylib -install_name @rpath/libZydis.4.0.dylib third-party/zydis/CMakeFiles/Zydis.dir/src/MetaInfo.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/Register.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/Segment.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/SharedData.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/String.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/Utils.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/Zydis.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/Decoder.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/DecoderData.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/Encoder.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/EncoderData.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/Disassembler.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/Formatter.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/FormatterBuffer.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/FormatterATT.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/FormatterBase.c.o third-party/zydis/CMakeFiles/Zydis.dir/src/FormatterIntel.c.o third-party/zydis/zycore/libZycore.a && :
ld: warning: pointer not aligned at _STR_MNEMONIC+0x9 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x12 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x1B from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x24 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x2D from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x36 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x3F from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x51 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x5A from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x63 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x6C from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x75 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x7E from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x87 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0x99 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0xA2 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0xAB from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0xB4 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o
ld: warning: pointer not aligned at _STR_MNEMONIC+0xBD from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/Mnemonic.c.o

ld: warning: pointer not aligned at _STR_PREF_REX_4E+0x0 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/FormatterBase.c.o
ld: warning: pointer not aligned at _STR_PREF_REX_4F+0x0 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/FormatterBase.c.o
ld: warning: pointer not aligned at _STR_ADD+0x0 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/FormatterIntel.c.o
ld: warning: pointer not aligned at _STR_MUL+0x0 from /Users/jamesaldridge/dev/jak-project-v-update-zydis/build/third-party/zydis/CMakeFiles/Zydis.dir/src/FormatterIntel.c.o
ld: pointer not 4-byte aligned at __DATA_CONST+0x39, fix alignment or disable chained fixups
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.`

Originally posted by @JamesAldridge in #350 (comment)

@flobernd flobernd added the A-build Area: Build system label Jan 16, 2024
@flobernd
Copy link
Member

Hi @JamesAldridge , like @athre0z mentioned in the original issue, we don't have Intel based Mac hardware available to test this. Could you please help us debugging?

The relevant code is located here:

#if !(defined(ZYAN_AARCH64) && defined(ZYAN_APPLE))
# pragma pack(push, 1)
#endif
/**
* Defines the `ZydisShortString` struct.
*
* This compact struct is mainly used for internal string-tables to save up some bytes.
*
* All fields in this struct should be considered as "private". Any changes may lead to unexpected
* behavior.
*/
typedef struct ZydisShortString_
{
/**
* The buffer that contains the actual (null-terminated) string.
*/
const char* data;
/**
* The length (number of characters) of the string (without 0-termination).
*/
ZyanU8 size;
} ZydisShortString;
#if !(defined(ZYAN_AARCH64) && defined(ZYAN_APPLE))
# pragma pack(pop)
#endif

As you can see, we are already using a guard to disable packing for AARCH64 on APPLE:

#if !(defined(ZYAN_AARCH64) && defined(ZYAN_APPLE))
#   pragma pack(push, 1)
#endif

Are these macros defined for you when you are building the library?

This is how we define these macros:

@athre0z
Copy link
Member

athre0z commented Jan 16, 2024

I think we just have to get rid of the ARM64 portion of the check and simply do:

#if !defined(ZYAN_APPLE)

I originally assumed that this was only an issue on aarch64 targets where Apple does pointer authentication, but it looks like the toolchain also complains about it on Intel.

@JamesAldridge
Copy link
Author

JamesAldridge commented Jan 16, 2024

Only ZYAN_APPLE and ZYAN_X64 are defined not ZYAN_AARCH64 when i build

@JamesAldridge
Copy link
Author

I think we just have to get rid of the ARM64 portion of the check and simply do:

#if !defined(ZYAN_APPLE)

I originally assumed that this was only an issue on aarch64 targets where Apple does pointer authentication, but it looks like the toolchain also complains about it on Intel.

That works, just tested

water111 pushed a commit to open-goal/jak-project that referenced this issue Jan 17, 2024
Fix zydis alignment issues when building on Intel macOS builds was
discussed with zydis devs zyantific/zydis#474

Verified locally that I can run open goal with the change.

Co-authored-by: JamesAldridge <jamesaldridge@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build Area: Build system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants