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#1973 musl: fix build on musl libc #7168

Merged
merged 18 commits into from
Jan 16, 2025
Merged

Conversation

ziyao233
Copy link
Member

This pull request allows DynamoRIO and all the tests to be built on musl libc,

  • Introduce MUSL macro and detect for musl libc in CMakeLists.txt
  • Add necessary macro and typedefs in core/unix/include/siginfo.h
  • Fix compilation of vendored elfutils
  • Temporarily use STDOUT/STDERR_FILENO when we need the underlying fds of
    stdout/stderr and suppress warnings for musl's opaque FILE type
  • Adjust linux.signal* tests to stay compatible with musl's SIGRTMAX, which is
    actually a function call, instead of a constant value

Tested on Alpine Linux, half of the tests are passed and it's possible to run
some applications (busybox, mutt and telegram-desktop) and some simple clients
(bbsize).

Issue: #1973

This introduces the MUSL macro.
bits/wordsize.h is a glibc-specific header, on musl __WORD_SIZE is
defined as LONG_BIT. This is okay since Linux kernel assumes the size
of long is equal to a machine word.
The pre-defined config.h is adjusted to match musl's features. We also
to build and link lib/error.c to provide functions for error message
handling.
As DynamoRIO enables -Werror by default, such warnings will prevent a
warning-aware build. Since we also issue a warnings during start up,
Let's remove it.
GCC on Alpine Linux enables "-Wtrampolines" by default, breaking the
test. Since Alpine is the most widely-used musl-based distribution, it's
worth to work around this: let's defaults to -Wno-trampoline on musl
systems.
Some glibc-specific APIs are used in the test, we need to port them to
musl.
DynamoRIO defines REG_* macros for compatibility with old clients, which
conflict with signal.h on musl. Use of pragma push_macro/pop_macro to
avoid messing musl's header up.
@ziyao233
Copy link
Member Author

@derekbruening thanks for your review

@abhinav92003
Copy link
Contributor

@derekbruening thanks for your review

If this PR is ready for review, please add a reviewer from the "Reviewers" list on the top-right1.

@ziyao233
Copy link
Member Author

@derekbruening thanks for your review

If this PR is ready for review, please add a reviewer from the "Reviewers" list on the top-right1.

I have no write access to the repository, thus cannot require a reviewer :/
It's ready for review and I'll be thankful if you could give me a helpful hand.

CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
suite/tests/CMakeLists.txt Outdated Show resolved Hide resolved
suite/tests/linux/signal-base.h Outdated Show resolved Hide resolved
suite/tests/linux/signal-base.h Outdated Show resolved Hide resolved
suite/tests/linux/signal-base.h Outdated Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
core/unix/os.c Show resolved Hide resolved
@ziyao233 ziyao233 changed the title I#1973: fix build on musl libc i#1973: fix build on musl libc Jan 11, 2025
@ziyao233 ziyao233 changed the title i#1973: fix build on musl libc i#1973 musl: fix build on musl libc Jan 11, 2025
@ziyao233
Copy link
Member Author

ziyao233 commented Jan 11, 2025

btw, may I have write access to the repository? I'm an intern of ISCAS and will continue working on riscv and musl port for DR, the access will help a lot (like adding an appropriate reviewer)

@derekbruening
Copy link
Contributor

btw, may I have write access to the repository? I'm an intern of ISCAS and will continue working on riscv and musl port for DR, the access will help a lot (like adding an appropriate reviewer)

Yes, I sent an invitation.

core/unix/os.c Outdated Show resolved Hide resolved
@@ -381,6 +381,9 @@ nolibc_print(const char *str)
3,
# if defined(MACOS) || defined(ANDROID)
stderr->_file,
/* TODO i#1973: handle opaque FILE * on musl libc */
Copy link
Contributor

Choose a reason for hiding this comment

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

See PR #7190: Android64 needs this too. Let's remove the ifdefs and use STDERR_FILENO everywhere, for tools.c anyway. Not sure whether #7190 should do that first and this one merge or vice versa: please coordinate: @jackgallagher-arm

Copy link
Member Author

@ziyao233 ziyao233 Jan 16, 2025

Choose a reason for hiding this comment

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

Oops, I didn't see the comment and got it merged.

Copy link
Contributor

Choose a reason for hiding this comment

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

No problem, #7190 can put in code simplication here.

@ziyao233 ziyao233 merged commit fe1fb42 into DynamoRIO:master Jan 16, 2025
17 checks passed
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.

3 participants