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

loader: Provide memset, and use weak linkage instead of symbol renaming. #51682

Merged
merged 2 commits into from
Oct 13, 2023

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Oct 12, 2023

This ensures that the compiler may generate calls to these functions. Fixes #51680

Also, since we're using -ffreestanding for non-Windows platforms too, shouldn't the definitions of memset etc be put in loader_lib.c?

julia/cli/Makefile

Lines 10 to 11 in e949236

LOADER_CFLAGS = $(JCFLAGS) -I$(BUILDROOT)/src -I$(JULIAHOME)/src -I$(JULIAHOME)/src/support -I$(build_includedir) -ffreestanding
LOADER_LDFLAGS = $(JLDFLAGS) -ffreestanding -L$(build_shlibdir) -L$(build_libdir)

GCC requires the freestanding environment provide memcpy, memmove, memset and memcmp

cc @gbaraldi

This ensures that the compiler may generate calls to these functions.
@maleadt maleadt added domain:building Build system, or building Julia or its dependencies system:windows Affects only Windows labels Oct 12, 2023
@gbaraldi
Copy link
Member

Apparently we get them from libgcc on other platforms.

Copy link
Sponsor Member

@staticfloat staticfloat left a comment

Choose a reason for hiding this comment

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

I think this is an innovative solution, but I'd like @vtjnash to rubber-stamp this. My only concern is that we will need to follow the function signature of the "real" functions quite closely to avoid difficult-to-debug errors.

Copy link
Sponsor Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

IIRC, weak will interact very badly with loading shared libraries later. I think you just want JL_HIDDEN here?

@gbaraldi
Copy link
Member

Though will the compiler find that?

@maleadt
Copy link
Member Author

maleadt commented Oct 13, 2023

__attribute__((hidden)) is not available on Windows, and JL_HIDDEN is a no-op:

julia/cli/loader.h

Lines 55 to 61 in 8a847d5

#ifdef _OS_WINDOWS_
# ifdef JL_LIBRARY_EXPORTS
# define JL_DLLEXPORT __declspec(dllexport)
# endif
# define JL_DLLIMPORT __declspec(dllimport)
#define JL_HIDDEN
#else

Or is that what you mean, i.e., that the default visibility would work fine for this?

@vtjnash
Copy link
Sponsor Member

vtjnash commented Oct 13, 2023

Default visibility is fine. It is what we do for the other interceptors too (eg float16 ABI correction)

@gbaraldi
Copy link
Member

Won't this override memcpy for the whole process though?

@vtjnash
Copy link
Sponsor Member

vtjnash commented Oct 13, 2023

No, the windows linker is (fortunately) incapable of causing such chaos

@maleadt maleadt merged commit 42fb22e into master Oct 13, 2023
6 checks passed
@maleadt maleadt deleted the tb/freestanding branch October 13, 2023 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:building Build system, or building Julia or its dependencies system:windows Affects only Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loader fails to build on MSYS2 (mingw-w64-x86_64) due to compiler-generated memset
4 participants