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

GPUCompiler.compile replaces dots with underscores in extern functions #464

Closed
giordano opened this issue Jun 4, 2023 · 0 comments · Fixed by #465
Closed

GPUCompiler.compile replaces dots with underscores in extern functions #464

giordano opened this issue Jun 4, 2023 · 0 comments · Fixed by #465

Comments

@giordano
Copy link
Contributor

giordano commented Jun 4, 2023

using GPUCompiler

f() = ccall("extern foo.bar", llvmcall, Nothing, ())
struct MyCompilerParams <: AbstractCompilerParams end

GPUCompiler.runtime_module(::CompilerJob{<:Any,MyCompilerParams}) = @__MODULE__
GPUCompiler.isintrinsic(@nospecialize(job::CompilerJob{<:Any,MyCompilerParams}), fn::String) =
    contains(fn, r"foo.bar")

target = NativeCompilerTarget()
source = methodinstance(typeof(f), Tuple{})
config = CompilerConfig(target, MyCompilerParams())
job = CompilerJob(source, config)
llvm_ir = JuliaContext() do ctx
    string(GPUCompiler.compile(:llvm, job; ctx)[1])
end

results in

; ModuleID = 'start'
source_filename = "start"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-linux-gnu"

define void @_Z1f() local_unnamed_addr #0 !dbg !5 {
top:
  call void @foo_bar(), !dbg !8
  ret void, !dbg !8
}

declare void @foo_bar() local_unnamed_addr

attributes #0 = { "frame-pointer"="all" "probe-stack"="inline-asm" }

!llvm.module.flags = !{!0, !1}
!llvm.dbg.cu = !{!2}
!julia.kernel = !{!4}

!0 = !{i32 2, !"Dwarf Version", i32 4}
!1 = !{i32 2, !"Debug Info Version", i32 3}
!2 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !3, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, nameTableKind: None)
!3 = !DIFile(filename: "/tmp/foo.jl", directory: ".")
!4 = !{void ()* @_Z1f}
!5 = distinct !DISubprogram(name: "f", linkageName: "julia_f_936", scope: null, file: !3, line: 3, type: !6, scopeLine: 3, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !7)
!6 = !DISubroutineType(types: !7)
!7 = !{}
!8 = !DILocation(line: 3, scope: !5)

Note that the call to foo.bar became foo_bar, despite the fact code_llvm retains the dot:

julia> code_llvm(f, ())
;  @ /tmp/foo.jl:3 within `f`
define void @julia_f_999() #0 {
top:
  call void @foo.bar()
  ret void
}

and trying to call the function fails with

julia> f()
JIT session error: Symbols not found: [ foo.bar ]
JIT session error: Symbols not found: [ foo.bar ]

[9451] signal (11.1): Segmentation fault

The dot is still there.

@giordano giordano changed the title GPUCompiler.compile replaces dots with underscores GPUCompiler.compile replaces dots with underscores in extern functions Jun 4, 2023
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 a pull request may close this issue.

1 participant