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#7226: Move some macros used in .asm files into header files. #7202

Merged
merged 28 commits into from
Jan 27, 2025

Conversation

egrimley-arm
Copy link
Contributor

@egrimley-arm egrimley-arm commented Jan 21, 2025

The macros are defined in asm_offsetsx.h and the values are checked at compile time by asm_offsets.c.

A few other changes were needed to make this work:

  • Some declarations are moved from mangle.c into a new file mangle_aarch64.h.

  • A declaration is moved from module_elf.c to module_private.h.

Issue: #7226

The macros are defined in offsets.h and the values are checked
at compile time by offsets.c.

Change-Id: I0a22ae5c0046769dc3fb763db8904d52530e48af
@egrimley-arm
Copy link
Contributor Author

One could use a helper program on the host to automatically generate the header files that define the offsets, but that would be much more complex to implement and an ongoing maintenance burden in the build system. Since these offsets are very rarely changed, and any change of them will typically involve simultaneous intricate changes to assembly and code that generates assembly I don't think it makes sense to generate the header files automatically. Better just to check the values with something like this approach.

One could use the preprocessor to make the source slightly simpler in a way, but it would then be much more complex in another way, and the error message when an offset is incorrect would be less readable, I think. Currently the error message looks like this:

.../dynamorio/core/arch/aarch64/offsets.c:9:9: error: size of array ‘x1’ is negative
    9 |     int x1[dcontext_t_OFFSET_dstack == offsetof(dcontext_t, dstack) ? 1 : -1];

I think that makes perfect sense to a programmer, and, if not, there's the comment preceding it in the source.

Another option would be to generate an error message at run time. You would then have total control over what the message looks like, but an error at build time seems better.

And using static_assert is certainly worth considering. I'm a bit confused about which versions of static_assert (or _Static_assert or whatever) are available with which versions of which compilers, and which header files need to be included to make them work, so perhaps for DynamoRIO it's better to use something totally portable like this array length trick.

Change-Id: If271ed6c8c97ee5e636d2d7c2b012898812cbc28
Move some macros used in .asm files into header files.

The macros are defined in offsets.h and the values are checked
at compile time by offsets.cpp.

Change-Id: If903c6cb8128ca955979eaba5c2d6eaf68374259
Change-Id: If0598cd9327ce075f77c20839dd9bad312a9f96e
Change-Id: Ibbd01c543f8a162557640142d488efd63589d2f2
Change-Id: I300e728dac8d4ca30c72d1b12f366b91c007fa7d
Change-Id: I008235196859c32ec4c2a9891cdbb4e9a6f63d2f
Change-Id: Ie574980db7deb75db6647005443915828147d274
@egrimley-arm
Copy link
Contributor Author

Does this (/~https://github.com/DynamoRIO/dynamorio/actions/runs/12928500203/job/36055907604?pr=7202) make any sense to anyone?

aarch64-on-x86: **** 6 build errors ****
	/.../dynamorio/core/unix/../ir/opnd_api.h:47:6: error: #error REG_ enum conflict between DR and ucontext.h! Use DR_REG_ constants instead.
	make[2]: *** [core/CMakeFiles/dynamorio.dir/build.make:1021: core/CMakeFiles/dynamorio.dir/arch/aarch64/asm_offsets.cpp.o] Error 1

I don't understand how it's getting from #include "../globals.h" to including opnd_api.h, and there are other files which start by including globals.h. The error doesn't happen with my toolchain so it's hard for me to investigate.

"#error REG_ enum conflict between DR and ucontext.h! Use DR_REG_ constants instead."

Change-Id: I06cea0f27cc0cd817cd40228350ec2303e91d53f
It was added by 96cfabc in Oct 2010 and might not be useful any more?

Change-Id: I89564eca250bd8e12745f0523874ec8b0807722f
It was also necessary to move some declarations around.

Change-Id: Ib4c0419ae8332150a7b3cc476840384cf83e9e0e
Change-Id: Ie0d7d560a9e3579153e940f5cad851f442a02d6e
Change-Id: Ic1d3496ae991945c0666f8b2b026613d58872086
Change-Id: I4ae09c88f13a4778c09689cce5d5ac0a07762e4f
Change-Id: I3fb53b7067c44f02f80f1116331a907bf3bb5cbc
Change-Id: I28739ad149745f7dc4a9f3ffb3c918dabe14b4d4
Change-Id: I512ec112719549def9f90cd72f7a5316c5bec51a
Change-Id: I0b19252b3f8cc7e74285302d293ffa2a5d550590
Change-Id: I7f38fcc05eb8f923ca8a6ff35ff200b5bc82455e
Change-Id: I6a163c1375d7b661cd7993fdf67fc7d99fdf448e
@egrimley-arm egrimley-arm changed the title Move some macros used in .asm files into header files. i#7226: Move some macros used in .asm files into header files. Jan 27, 2025
Change-Id: I87304cd0c963a5de26bec3d28618a4170b4137bc
Change-Id: I011710a7634471237b33c9d4c0cac2f959c7a0a3
Change-Id: Id6e32d70c9f2705c39f2f423f83fa210c779e78d
Change-Id: Icbad0e3d2346bb078bc5c344aeb0bb1bc669bdbb
@egrimley-arm egrimley-arm merged commit 2f2614b into master Jan 27, 2025
17 checks passed
@egrimley-arm egrimley-arm deleted the iX-offsets branch January 27, 2025 21:06
jackgallagher-arm added a commit that referenced this pull request Jan 30, 2025
Fixes a compile error for Android64 introduced by #7202
(commit 2f2614b):
```
core/arch/aarch64/asm_offsetsx.h:85:1: error: offsetof of incomplete type 'struct tlsdesc_t'
   85 | OFFSET(struct tlsdesc_t, arg, 8)
      | ^      ~~~~~~
```

`tlsdesc_t` is not defined on Android.

Issues: #2154, #7226
jackgallagher-arm added a commit that referenced this pull request Jan 31, 2025
Fixes a compile error for Android64 introduced by #7202 (commit
2f2614b):
```
core/arch/aarch64/asm_offsetsx.h:85:1: error: offsetof of incomplete type 'struct tlsdesc_t'
   85 | OFFSET(struct tlsdesc_t, arg, 8)
      | ^      ~~~~~~
```

`tlsdesc_t` is not defined on Android.

Issues: #2154, #7226
derekbruening added a commit that referenced this pull request Feb 11, 2025
Solves a missing header issue that results in a build error on Mac M1
with the new asm offset files from PR #7202: module.h has to be
included before module_private.h so we explicitly include the former
in the latter.

Issue: #7226
derekbruening added a commit that referenced this pull request Feb 11, 2025
Solves a missing header issue that results in a build error on Mac M1
with the new asm offset files from PR #7202: module.h has to be included
before module_private.h so we explicitly include the former in the
latter. Tested locally on M1 Mac.

Issue: #7226
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