Skip to content

Better support for linux kernel#62

Merged
flobernd merged 2 commits intozyantific:masterfrom
jpidancet:master
Mar 3, 2023
Merged

Better support for linux kernel#62
flobernd merged 2 commits intozyantific:masterfrom
jpidancet:master

Conversation

@jpidancet
Copy link
Copy Markdown
Contributor

@jpidancet jpidancet commented Feb 28, 2023

Hi,

These two commits improve support for building Zydis for the linux kernel in a couple of corner cases:

The first commit introduces the ZYAN_DIV64 macro to fix a failure when linking Zydis on a 32bit linux kernel. The Zydis changes will be submitted in a separate PR.

The second PR adds support for building Zydis in NO_LIBC mode with old versions of GCC.

Thanks,

Add a macro for dividing 64bit numbers.

With 32bit linux targets, GCC generates a call to __udivdi3 when
dividing 64bit integers, even when compiling in freestanding mode.
However, the __udivdi3 implementation resides in libgcc which is not
linked-in when building kernel code.

Besides, the Linux kernel voluntarily doesn't implement __udivdi3 to
force developers to use the do_div macro instead [1].

[1] https://lwn.net/Articles/456689/
Fallback to custom defined types when __*_TYPE__ macros are not defined
on GCC.

Old versions of GCC such as version 4.4.7 and prior do not define the
__*_TYPE__ macros, so provide custom type definition when building
without libc headers [1].

Also add custom definition for ZYAN_*_MAX and ZYAN_*_MIN values as
__*_MAX__ macros are also missing for the same reason [2].

[1] https://godbolt.org/z/j5Yhs48z9
[2] https://godbolt.org/z/1TvjTd5Ga
@flobernd
Copy link
Copy Markdown
Member

Thanks for your PR! Will have a detailed look tomorrow. cc @athre0z

@flobernd
Copy link
Copy Markdown
Member

flobernd commented Mar 3, 2023

Sorry for the delay. LGTM! Thanks again.

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