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

Compiler crashes with LLVM error #3774

Open
marcs-feh opened this issue Jun 16, 2024 · 3 comments
Open

Compiler crashes with LLVM error #3774

marcs-feh opened this issue Jun 16, 2024 · 3 comments

Comments

@marcs-feh
Copy link
Contributor

marcs-feh commented Jun 16, 2024

Context

In a utility function to be able to use the Spall debugger:

@(deferred_out=profiler_end)
profiler_start :: proc() -> (^spall.Context, ^spall.Buffer, []byte){
	@static spall_ctx: spall.Context
	@static spall_buffer: spall.Buffer

	profiler_mem := make([]byte, 200 * mem.Megabyte)
	spall_buffer = spall.buffer_create(profiler_mem)
	spall_ctx, _ = spall.context_create("profile.spall")

	@(instrumentation_enter)
	spall_enter :: proc "contextless" (proc_address, call_site_return_address: rawptr, loc: runtime.Source_Code_Location) {
		spall._buffer_begin(&spall_ctx, &spall_buffer, "", "", loc)
	}
	@(instrumentation_exit)
	spall_exit :: proc "contextless" (proc_address, call_site_return_address: rawptr, loc: runtime.Source_Code_Location) {
		spall._buffer_end(&spall_ctx, &spall_buffer)
	}

	return &spall_ctx, &spall_buffer, profiler_mem
}

profiler_end :: proc(spall_ctx: ^spall.Context, spall_buffer: ^spall.Buffer, buf: []byte){
	spall.buffer_destroy(spall_ctx, spall_buffer)
	spall.context_destroy(spall_ctx)
	delete(buf)
}

Expected Behavior

Proper compilation or a odin compiler error.

Current Behavior

The compiler crashes with the following message:

LLVM Error:
Global is external, but doesn't have external or weak linkage!
ptr @imgui.spall_enter-28467
Global is external, but doesn't have external or weak linkage!
ptr @imgui.spall_exit-28468

A very weird thing also happens when using a when statement, doing this:

ENABLE_PROFILER :: #config(ENABLE_PROFILER, true)

when ENABLE_PROFILER {
// Same 2 functions as above...
}

Doing this somehow completely fixes the issue.

Steps to Reproduce

Copying the context code and trying to use it should be enough

Odin report output

        Odin:    dev-2024-06:f280ba851
        OS:      Arch Linux, Linux 6.6.31-1-lts
        CPU:     AMD Ryzen 3 3200G with Radeon Vega Graphics
        RAM:     15922 MiB
        Backend: LLVM 17.0.5
@laytan
Copy link
Sponsor Collaborator

laytan commented Jun 16, 2024

Adding @instrumentation_enter and exit attributes on a non-global should probably be a compile error

@marcs-feh
Copy link
Contributor Author

Adding @instrumentation_enter and exit attributes on a non-global should probably be a compile error

I agree, but the interaction with when is really weird, how does doing conditional compilation change the inner procedure in some way that might cause it to somehow function properly?

@laytan
Copy link
Sponsor Collaborator

laytan commented Jun 16, 2024

Adding @instrumentation_enter and exit attributes on a non-global should probably be a compile error

I agree, but the interaction with when is really weird, how does doing conditional compilation change the inner procedure in some way that might cause it to somehow function properly?

That is indeed a weird interaction

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

No branches or pull requests

2 participants