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 fails on musl-libc based linux systems (for example alpine, void, sabotage) #1973

Open
rofl0r opened this issue Jul 15, 2016 · 6 comments

Comments

@rofl0r
Copy link

rofl0r commented Jul 15, 2016

dynamorio-release_6_1_1/core/unix/os.c: In function 'handle_close_pre':
dynamorio-release_6_1_1/core/unix/os.c:5620:30: error: dereferencing pointer to incomplete type
dynamorio-release_6_1_1/core/unix/os.c:5636:30: error: dereferencing pointer to incomplete type
dynamorio-release_6_1_1/core/unix/os.c:5652:29: error: dereferencing pointer to incomplete type
make[2]: *** [core/CMakeFiles/dynamorio.dir/unix/os.c.o] Error 1

the code in question is

            /* update the privately loaded libc's stdout _fileno. */
            (*privmod_stdout)->STDFILE_FILENO = our_stdout;                     


            /* update the privately loaded libc's stderr _fileno. */            
            (*privmod_stderr)->STDFILE_FILENO = our_stderr;


            /* update the privately loaded libc's stdout _fileno. */            
            (*privmod_stdin)->STDFILE_FILENO = our_stdin;

FILE is an opaque type and it's illegal to make assumptions about or access the underlying struct from non-libc code.
I'm currently talking with musl's author if there's a portable solution.
the code in question was introduced to fix #261

@rofl0r
Copy link
Author

rofl0r commented Jul 15, 2016

a possible solution could be to use separate fds for the logging purposes rather than hijacking the ones of the app.

@derekbruening
Copy link
Contributor

Unfortunately it is sometimes unavoidable to break abstractions and take "illegal" steps for low-level systems like DR, in this case to load a private copy of libc and isolate it from the app's copy.

I don't think tools are willing to give up printing directly to stdout or stderr: interleaving tool output with app output can be very valuable for a tool user.

@rofl0r
Copy link
Author

rofl0r commented Jul 15, 2016

can you elaborate about "load a private copy of libc and isolate it from the app's copy" ?
i think this is highly problematic especially with regard to the global state of the memory allocator.

@derekbruening
Copy link
Contributor

Malloc & co. are redirected to DR's own allocator. See http://dynamorio.org/docs/using.html#sec_extlibs

@egrimley
Copy link
Contributor

egrimley commented May 3, 2017

Presumably there is no portable way of doing this redirection of a stream. There's fdopen() for converting a file descriptor into a stream, and there's freopen() for redirecting an existing stream to a new file, but there doesn't seem to be a way of redirecting an existing stream to an existing stream or file descriptor.

@rofl0r
Copy link
Author

rofl0r commented May 3, 2017

in that case may i suggest that this feature only gets activated if the non-portable prerequisites exist ? for example by doing a configure check.

derekbruening pushed a commit that referenced this issue Apr 12, 2018
These changes seem sufficient to allow building dynamorio on an alpine linux container, and to successfully run some basic clients.  No further testing was done.  While this can successfully build against musl, there are probably some things broken at runtime.

Issue: #1973
ziyao233 added a commit that referenced this issue Jan 16, 2025
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
ziyao233 added a commit that referenced this issue Feb 4, 2025
POSIX.1 requires SS_ONSTACK to appear only in a stack_t retrieved from
sigaltstack(), not one passed to it. musl checks the invalid flag and
will
bail out with EINVAL before issuing a syscall in this case, failing the
test.

This commit sets ss_flags to zero instead, on both glibc and musl this
should issue a syscall, which fixes assertion failures encountered in
linux.signal*, api.static_signal and drcachesim.burst_threads on musl.

Issue: #1973
ziyao233 added a commit that referenced this issue Feb 5, 2025
The workflow constructs an Alpine Linux chroot environment in place and
build DynamoRIO in it, serving as compatibility verification against
musl. Tests are disabled in CI since only half of them pass.

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

No branches or pull requests

3 participants