<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">At this point gcroot is essentially
deprecated. It hasn't been officially deprecated and probably
won't be in the near future, but the only practical
user/contributor to LLVM GC support is using statepoint and the
related infrastructure. Not saying you need to change your
approach, but might be something you want to keep in mind.<br>
<br>
Philip<br>
<br>
On 11/01/2017 02:26 PM, Nikodemus Siivola via llvm-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CADow0Cp-xcRCQ1rmF10QbjKg8XbE=AoHtr_CnR5K9hxYyzqNEg@mail.gmail.com">
<div dir="ltr">Solved by using alloca i8*, i32 2 which the system
seems happy enough with, and bitcasting to the actual type for
rest of the code after llvm.gcroot.
<div><br>
</div>
<div>Not entirely sure if this is a terrible workaround or
exactly the way gcroot is supposed to be used...</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Wed, Nov 1, 2017 at 11:59 AM,
Nikodemus Siivola <span dir="ltr"><<a
href="mailto:nikodemus@random-state.net" target="_blank"
moz-do-not-send="true">nikodemus@random-state.net</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div>I'm allocating { i8*, i32 } on the stack, and would
like to add this as a GC root, but I'm having trouble
figuring this out.<br>
<br>
This works as expected:</div>
<div><br>
</div>
<div>
<div><font face="monospace, monospace">declare void
@llvm.gcroot(i8** %ptrloc, i8* %metadata)</font></div>
<div><font face="monospace, monospace"><br>
</font></div>
<div><font face="monospace, monospace">define i8*
@bar(i8* %x) gc "shadow-stack" {</font></div>
<div><font face="monospace, monospace">entry:</font></div>
<div><font face="monospace, monospace"> %objptr =
alloca i8*</font></div>
<div><font face="monospace, monospace"> call void
@llvm.gcroot(i8** %objptr, i8* null)</font></div>
<div><font face="monospace, monospace"> store i8* %x,
i8** %objptr</font></div>
<div><font face="monospace, monospace"> %v = load i8*,
i8** %objptr</font></div>
<div><font face="monospace, monospace"> ret i8* %v</font></div>
<div><font face="monospace, monospace">}</font></div>
</div>
<div><br>
</div>
<div>However, when I have this:<br>
<br>
<div><font face="monospace, monospace">define { i8*, i32
} @foo({ i8*, i32 } %x) gc "shadow-stack" {</font></div>
<div><font face="monospace, monospace">entry:</font></div>
<div><font face="monospace, monospace"> %objptr =
alloca { i8*, i32 }</font></div>
<div><font face="monospace, monospace"> %rootptr =
bitcast { i8*, i32 }* %objptr to i8**</font></div>
<div><font face="monospace, monospace"> call void
@llvm.gcroot(i8** %rootptr, i8* null)</font></div>
<div><font face="monospace, monospace"> store { i8*,
i32 } %x, { i8*, i32 }* %objptr</font></div>
<div><font face="monospace, monospace"> %v = load {
i8*, i32 }, { i8*, i32 }* %objptr</font></div>
<div><font face="monospace, monospace"> ret { i8*, i32
} %v</font></div>
<div><font face="monospace, monospace">}</font></div>
<div><br>
llc says: llvm.gcroot parameter #1 must either be a
pointer alloca, or argument #2 must be a non-null
constant.</div>
<div> call void @llvm.gcroot(i8** %rootptr, i8* null)</div>
<br>
...and if I do as it asks and add a metadata then I get
a crash:<br>
<br>
<div><font face="monospace, monospace">@info = constant
i8 1</font></div>
<div><font face="monospace, monospace"><br>
</font></div>
<div><font face="monospace, monospace">define { i8*, i32
} @quux({ i8*, i32 } %x) gc "shadow-stack" {</font></div>
<div><font face="monospace, monospace">entry:</font></div>
<div><font face="monospace, monospace"> %objptr =
alloca { i8*, i32 }</font></div>
<div><font face="monospace, monospace"> %rootptr =
bitcast { i8*, i32 }* %objptr to i8**</font></div>
<div><font face="monospace, monospace"> call void
@llvm.gcroot(i8** %rootptr, i8* @info)</font></div>
<div><font face="monospace, monospace"> store { i8*,
i32 } %x, { i8*, i32 }* %objptr</font></div>
<div><font face="monospace, monospace"> %v = load {
i8*, i32 }, { i8*, i32 }* %objptr</font></div>
<div><font face="monospace, monospace"> ret { i8*, i32
} %v</font></div>
<div><font face="monospace, monospace">}</font></div>
</div>
<div><br>
</div>
<div>leads llc into this:</div>
<div><br>
</div>
<div>
<div><font face="monospace, monospace">Assertion failed:
isa<X>(Val) && "cast<Ty>()
argument of incompatible type!", file
C:\Users\nikod\src\llvm\<wbr>include\llvm/Support/Casting.<wbr>h,
line 236</font></div>
<div><font face="monospace, monospace">Wrote crash dump
file "C:\Users\nikod\AppData\Local\<wbr>Temp\llc.exe-7b1546.dmp"</font></div>
<div><font face="monospace, monospace">#0 0x01a26809
HandleAbort c:\users\nikod\src\llvm\lib\<wbr>support\windows\signals.inc:<wbr>405:0</font></div>
<div><font face="monospace, monospace">#1 0x75804188
(C:\WINDOWS\System32\ucrtbase.<wbr>dll+0xa4188)</font></div>
<div><font face="monospace, monospace">#2 0x75805422
(C:\WINDOWS\System32\ucrtbase.<wbr>dll+0xa5422)</font></div>
<div><font face="monospace, monospace">#3 0x75806dc5
(C:\WINDOWS\System32\ucrtbase.<wbr>dll+0xa6dc5)</font></div>
<div><font face="monospace, monospace">#4 0x75806ce8
(C:\WINDOWS\System32\ucrtbase.<wbr>dll+0xa6ce8)</font></div>
<div><font face="monospace, monospace">#5 0x7580618b
(C:\WINDOWS\System32\ucrtbase.<wbr>dll+0xa618b)</font></div>
<div><font face="monospace, monospace">#6 0x75806e26
(C:\WINDOWS\System32\ucrtbase.<wbr>dll+0xa6e26)</font></div>
<div><font face="monospace, monospace">#7 0x013786a6
InsertRootInitializers c:\users\nikod\src\llvm\lib\<wbr>codegen\gcrootlowering.cpp:<wbr>172:0</font></div>
<div><font face="monospace, monospace">#8 0x01378d97
`anonymous namespace'::LowerIntrinsics::<wbr>PerformDefaultLowering
c:\users\nikod\src\llvm\lib\<wbr>codegen\gcrootlowering.cpp:<wbr>249:0</font></div>
<div><font face="monospace, monospace">#9 0x01379986
`anonymous namespace'::LowerIntrinsics::<wbr>runOnFunction
c:\users\nikod\src\llvm\lib\<wbr>codegen\gcrootlowering.cpp:<wbr>195:0</font></div>
<div><font face="monospace, monospace">#10 0x016a343c
llvm::FPPassManager::<wbr>runOnFunction(class
llvm::Function &) c:\users\nikod\src\llvm\lib\<wbr>ir\legacypassmanager.cpp:1513:<wbr>0</font></div>
<div><font face="monospace, monospace">#11 0x016a35e4
llvm::FPPassManager::<wbr>runOnModule(class
llvm::Module &) c:\users\nikod\src\llvm\lib\<wbr>ir\legacypassmanager.cpp:1533:<wbr>0</font></div>
<div><font face="monospace, monospace">#12 0x016a382c
`anonymous namespace'::MPPassManager::<wbr>runOnModule
c:\users\nikod\src\llvm\lib\<wbr>ir\legacypassmanager.cpp:1590:<wbr>0</font></div>
<div><font face="monospace, monospace">#13 0x016a2e0e
llvm::legacy::PassManagerImpl:<wbr>:run(class
llvm::Module &) c:\users\nikod\src\llvm\lib\<wbr>ir\legacypassmanager.cpp:1693:<wbr>0</font></div>
<div><font face="monospace, monospace">#14 0x01000a62
compileModule c:\users\nikod\src\llvm\tools\<wbr>llc\llc.cpp:534:0</font></div>
<div><font face="monospace, monospace">#15 0x010059ca
main c:\users\nikod\src\llvm\tools\<wbr>llc\llc.cpp:289:0</font></div>
<div><font face="monospace, monospace">#16 0x01be99e9
_scrt_common_main_seh f:\dd\vctools\crt\vcstartup\<wbr>src\startup\exe_common.inl:<wbr>253:0</font></div>
<div><font face="monospace, monospace">#17 0x77178744
(C:\WINDOWS\System32\KERNEL32.<wbr>DLL+0x18744)</font></div>
<div><font face="monospace, monospace">#18 0x7737582d
(C:\WINDOWS\SYSTEM32\ntdll.<wbr>dll+0x6582d)</font></div>
<div><font face="monospace, monospace">#19 0x773757fd
(C:\WINDOWS\SYSTEM32\ntdll.<wbr>dll+0x657fd)<br>
</font></div>
</div>
<div><font face="arial, helvetica, sans-serif"><br>
</font></div>
<div><font face="arial, helvetica, sans-serif">(This is
the same assertion failure that my full code produces,
and which lead me to trying out things with minimal
case and llc.)</font></div>
<div><font face="arial, helvetica, sans-serif"><br>
</font></div>
<div><font face="arial, helvetica, sans-serif">What I can
see in the debugger isn't immediately illuminating. </font><span
style="font-family:arial,helvetica,sans-serif">Any
clues? Am I missing the obvious here?</span></div>
<div><span style="font-family:arial,helvetica,sans-serif"><br>
</span></div>
<div><span style="font-family:arial,helvetica,sans-serif">This
is:</span></div>
<div><font face="arial, helvetica, sans-serif"><br>
<div>LLVM (<a href="http://llvm.org/" target="_blank"
moz-do-not-send="true">http://llvm.org/</a>):</div>
<div> LLVM version 4.0.1</div>
<div> DEBUG build with assertions.</div>
<div> Default target: i686-pc-windows-msvc</div>
<div> Host CPU: skylake</div>
<br>
Cheers,</font></div>
<div><font face="arial, helvetica, sans-serif"><br>
</font></div>
<div><font face="arial, helvetica, sans-serif"> --
nikodemus</font></div>
<div><font face="arial, helvetica, sans-serif"><br>
</font></div>
</div>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<p><br>
</p>
</body>
</html>