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

[WRAPPED] Added monstartup #2241

Merged
merged 5 commits into from
Jan 8, 2025
Merged

[WRAPPED] Added monstartup #2241

merged 5 commits into from
Jan 8, 2025

Conversation

xiangzhai
Copy link
Contributor

Hi,

before:

Error: Symbol monstartup not found, cannot apply R_X86_64_JUMP_SLOT @0x3f096d4ef0 (0x4b346) in /yourpath/x64.so
Error: relocating Plt symbols in elf x64.so
Error initializing needed lib /yourpath/x64.so
Exception in thread "main" java.lang.ExceptionInInitializerError: initialization failed with java.lang.UnsatisfiedLinkError: /yourpath/x64.so: Cannot dlopen("/yourpath/x64.so"/0xffec4ba3b0, 1)

after:
work :)

Please review my patch.

Thanks,
Leslie Zhai

@xiangzhai xiangzhai marked this pull request as draft January 8, 2025 08:32
@xiangzhai xiangzhai marked this pull request as ready for review January 8, 2025 08:50
#ifdef STATICBUILD
//GO(monstartup, iFpp)
#else
GO(monstartup, iFpp)
Copy link
Owner

@ptitSeb ptitSeb Jan 8, 2025

Choose a reason for hiding this comment

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

The doc I found state this:

       void
       monstartup(u_long lowpc,	u_long highpc);

and my local include file is similar.
so, signature should be vFLL instead. Were did you found iFpp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

int monstartup(caddr_t LowProgramCounter, caddr_t HighProgramCounter);

https://www.ibm.com/docs/zh-tw/aix/7.1?topic=m-monstartup-subroutine

And caddr_t:

typedef char *__caddr_t;
typedef __caddr_t caddr_t;

Thanks,
Leslie Zhai

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ptitSeb you are correct:

/usr/include/loongarch64-linux-gnu/sys/gmon.h:194:extern void monstartup (unsigned long __lowpc, unsigned long __highpc) __THROW;

Thanks,
Leslie Zhai

@ksco
Copy link
Collaborator

ksco commented Jan 8, 2025

Check this tutorial for the basics of libwrapping: https://box86.org/2024/02/how-to-create-a-wrapping/

@xiangzhai xiangzhai requested a review from ptitSeb January 8, 2025 09:53
@xiangzhai
Copy link
Contributor Author

And it should use GO but not GOW, because the symbol monstartup is not STB_WEAK:

Error: Symbol monstartup not found, cannot apply R_X86_64_JUMP_SLOT @0x3f096d4ef0 (0x4b346) in /yourpath/x64.so

https://github.com/ptitSeb/box64/blob/main/src/elfs/elfloader.c#L713

Please point out my fault.

Thanks,
Leslie Zhai

@ptitSeb
Copy link
Owner

ptitSeb commented Jan 8, 2025

And it should use GO but not GOW, because the symbol monstartup is not STB_WEAK:

Error: Symbol monstartup not found, cannot apply R_X86_64_JUMP_SLOT @0x3f096d4ef0 (0x4b346) in /yourpath/x64.so

https://github.com/ptitSeb/box64/blob/main/src/elfs/elfloader.c#L713

Please point out my fault.

Thanks, Leslie Zhai

For static build, you might need to look at static_libc.h and create the function signature there.

@ptitSeb
Copy link
Owner

ptitSeb commented Jan 8, 2025

And it should use GO but not GOW, because the symbol monstartup is not STB_WEAK:

Error: Symbol monstartup not found, cannot apply R_X86_64_JUMP_SLOT @0x3f096d4ef0 (0x4b346) in /yourpath/x64.so

https://github.com/ptitSeb/box64/blob/main/src/elfs/elfloader.c#L713

Please point out my fault.

Thanks, Leslie Zhai

On my system, that symbol is Weak:

seb@D2000:/data/Games/x86$ nm -D /usr/lib/aarch64-linux-gnu/libc.so.6 | grep monstartup
00000000000f2780 T __monstartup@@GLIBC_2.17
00000000000f2780 W monstartup@@GLIBC_2.17

@xiangzhai xiangzhai marked this pull request as draft January 8, 2025 11:16
@xiangzhai
Copy link
Contributor Author

xiangzhai commented Jan 8, 2025

Hi @ptitSeb please wait for my local staticbuild test.

Thanks,
Leslie Zhai

@xiangzhai
Copy link
Contributor Author

On my system, that symbol is Weak:

seb@D2000:/data/Games/x86$ nm -D /usr/lib/aarch64-linux-gnu/libc.so.6 | grep monstartup
00000000000f2780 T __monstartup@@GLIBC_2.17
00000000000f2780 W monstartup@@GLIBC_2.17

Thanks for pointing out my fault monstartup is WEAK symbol:

$ nm -D /usr/lib/loongarch64-linux-gnu/libc.so.6 |grep monstartup
00000000000dfd40 T __monstartup
00000000000dfd40 W monstartup

@xiangzhai xiangzhai marked this pull request as ready for review January 8, 2025 11:55
@xiangzhai xiangzhai requested a review from ptitSeb January 8, 2025 11:55
@ptitSeb ptitSeb merged commit c65910f into ptitSeb:main Jan 8, 2025
27 checks passed
@xiangzhai xiangzhai deleted the wrapped_mon branch January 10, 2025 01:24
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