You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When mlibc is built as a static library functions that are marked as weak with [[gnu::weak]] sometimes aren't included in the final executable. Namely I implemented sys_ttyname and sys_isatty in sysdeps/rook/generic/posix.cpp, both functions are declared in options/posix/include/mlibc/posix-sysdeps.h. Running the final executable causes MLIBC_CHECK_OR_ENOSYS to fail on line 764 in options/posix/generic/unistd-stubs.cpp because the mlibc::sys_ttyname function is not found meaning the weak symbol is undefined. If I move the function definitions to sysdeps/rook/generic/generic.cpp the executable is linked properly and MLIBC_CHECK_OR_ENOSYS does not fail.
Symbols and build file
symbols when functions are defined in posix.cpp:
$ nm root/bin/bash | grep ttyname
00000000004da6aa T ttyname
00000000004da76a T ttyname_r
0000000000000084 b _ZZ7ttynameE3buf
$ nm root/usr/lib/libc.a | grep ttyname
000000000000001b W _ZN5mlibc11sys_ttynameEiPcm
0000000000002d6d T ttyname
0000000000002e2d T ttyname_r
w _ZN5mlibc11sys_ttynameEiPcm
0000000000000000 b _ZZ7ttynameE3buf
symbols when functions are defined in generic.cpp:
$ nm root/bin/bash | grep ttyname
00000000004da6aa T ttyname
00000000004da76a T ttyname_r
000000000051f6b6 W _ZN5mlibc11sys_ttynameEiPcm
0000000000000084 b _ZZ7ttynameE3buf
$ nm root/usr/lib/libc.a | grep ttyname
0000000000000276 W _ZN5mlibc11sys_ttynameEiPcm
0000000000002d6d T ttyname
0000000000002e2d T ttyname_r
w _ZN5mlibc11sys_ttynameEiPcm
0000000000000000 b _ZZ7ttynameE3buf
changing the order of the files in libc_sources didn't work
both files include the exact same headers in the exact same order
the functions were in the right namespace in both files and their function signatures, mangled symbol names matched which can be confirmed by comparing the outputs of nm which i provided above
the function body is irrelevant, whether it was a stub or the function was actually implemented didn't make a difference
in both cases the right symbols exist in the static library but at different addresses
Temporary solutions
removing the '[[gnu:weak]]' attribute from the 2 function declarations in the header file thus changing it to a strong symbol
putting all function definitions in the same source file
The text was updated successfully, but these errors were encountered:
Description
When mlibc is built as a static library functions that are marked as weak with
[[gnu::weak]]
sometimes aren't included in the final executable. Namely I implementedsys_ttyname
andsys_isatty
insysdeps/rook/generic/posix.cpp
, both functions are declared inoptions/posix/include/mlibc/posix-sysdeps.h
. Running the final executable causesMLIBC_CHECK_OR_ENOSYS
to fail on line 764 inoptions/posix/generic/unistd-stubs.cpp
because themlibc::sys_ttyname
function is not found meaning the weak symbol is undefined. If I move the function definitions tosysdeps/rook/generic/generic.cpp
the executable is linked properly andMLIBC_CHECK_OR_ENOSYS
does not fail.Symbols and build file
symbols when functions are defined in posix.cpp:
symbols when functions are defined in generic.cpp:
meson.build
Details
libc_sources
didn't worknm
which i provided aboveTemporary solutions
The text was updated successfully, but these errors were encountered: