ldc
ldc copied to clipboard
riscv{32,64}-unknown-linux-musl runtime error
import core.stdc.stdio;
extern(C) int main(int argc, char** argv){
printf("argc=%d\n", argc);
return 0;
}
ldc2 -betterC -mtriple=risc64-unknown-linux-musl test.d
/ldc/bin/../import/core/stdc/stdio.d(1464): Error: `pragma(printf)` function `vfprintf` must have signature `int vfprintf([parameters...], const(char)*, va_list)`
/ldc/bin/../import/core/stdc/stdio.d(1467): Error: `pragma(scanf)` function `vfscanf` must have signature `int vfscanf([parameters...], const(char)*, va_list)`
/ldc/bin/../import/core/stdc/stdio.d(1470): Error: `pragma(printf)` function `vsprintf` must have signature `int vsprintf([parameters...], const(char)*, va_list)`
/ldc/bin/../import/core/stdc/stdio.d(1473): Error: `pragma(scanf)` function `vsscanf` must have signature `int vsscanf([parameters...], const(char)*, va_list)`
/ldc/bin/../import/core/stdc/stdio.d(1476): Error: `pragma(printf)` function `vprintf` must have signature `int vprintf([parameters...], const(char)*, va_list)`
/ldc/bin/../import/core/stdc/stdio.d(1479): Error: `pragma(scanf)` function `vscanf` must have signature `int vscanf([parameters...], const(char)*, va_list)`
/ldc/bin/../import/core/stdc/stdio.d(1979): Error: `pragma(printf)` function `vsnprintf` must have signature `int vsnprintf([parameters...], const(char)*, va_list)`
ldc2 -betterC -mtriple=riscv64-unknown-linux-musl -c core/sys/posix/signal.d
/ldc/import/core/sys/posix/signal.d(2767): Error: static assert: "unimplemented"
static assert(0, "unimplemented");
Please file upstream.
Sorry, I will report druntime related into upstream in future. this one is reported.
this patch fix the riscv64-unknown-linux-musl druntime
diff --git a/core/sys/posix/signal.d b/core/sys/posix/signal.d
index e3d80fb..9c0e423 100644
--- a/core/sys/posix/signal.d
+++ b/core/sys/posix/signal.d
@@ -2763,6 +2763,11 @@ else version (CRuntime_Musl)
enum MINSIGSTKSZ = 4096;
enum SIGSTKSZ = 16384;
}
+ else version (RISCV_Any)
+ {
+ enum MINSIGSTKSZ = 2048;
+ enum SIGSTKSZ = 8192;
+ }
else
static assert(0, "unimplemented");
but I get a warning like this:
ldc2 -mtriple=riscv64-unknown-linux-musl --target-abi=lp64d -mattr=+zba,+zbb,+zbc,+zbs test.d
Hard-float 'd' ABI can't be used for a target that doesn't support the D instruction set extension (ignoring target-abi)
Hard-float 'd' ABI can't be used for a target that doesn't support the D instruction set extension (ignoring target-abi)
after add Hard-float 'd' ABI, then I can build for https://github.com/libriscv/libriscv with ldc2. (it can be used for game plugin, hard-float is required for good performance)
ldc2 -mtriple=riscv64-unknown-linux-musl --target-abi=lp64d -mattr=+zba,+zbb,+zbc,+zbs --float-abi=hard test.d with lto link there will be error:
cannot link object files with different floating-point ABI from /risc64/bin/../sysroot/lib/crt1.o
with -mattr=+d skip this warning:
Hard-float 'd' ABI can't be used for a target that doesn't support the D instruction set extension (ignoring target-abi)
Hard-float 'd' ABI can't be used for a target that doesn't support the D instruction set extension (ignoring target-abi)
still get lto link error.
the clang sysroot/lib/crt1.o:
Attribute Section: riscv
File Attributes
Tag_RISCV_stack_align: 16-bytes
Tag_RISCV_arch: "rv64i2p1_m2p0_a2p1_f2p2_d2p2_zicsr2p0_zifencei2p0_zmmul1p0_zaamo1p0_zalrsc1p0_zba1p0_zbb1p0_zbc1p0_zbs1p0"
ldc2 lto object:
Attribute Section: riscv
File Attributes
Tag_RISCV_stack_align: 16-bytes
Tag_RISCV_arch: "rv64i2p1_f2p2_d2p2_zicsr2p0_zba1p0_zbb1p0_zbc1p0_zbs1p0"
with -mattr=+m,+a,+f,+d,+zicsr,+zifencei,+zmmul,+zaamo,+zalrsc,+zba,+zbb,+zbc,+zbs get same Tag_RISCV_arch like sysroot/lib/crt1.o but still get error:
cannot link object files with different floating-point ABI from sysroot/lib/crt1.o
I think you want -mabi=lp64d, not -target-abi - the latter is a (recent) LLVM option which we forgot to hide (I've only seen this recently, along with a bunch of other new LLVM options - will be fixed when merging the LLVM-20 PR).
It still same error.
I report wrong 'ldc2 lto object arch' (it is read from without lto object), the object with lto create by ldc2 is LLVM bitcode file. and the llvm-bcanalyzer result is
Summary of test.o:
Total size: 709760b/88720.00B/22180W
Stream type: LLVM IR
# Toplevel Blocks: 4
Per-block Summary:
Block ID #0 (BLOCKINFO_BLOCK):
Num Instances: 1
Total Size: 864b/108.00B/27W
Percent of file: 0.1217%
Num SubBlocks: 0
Num Abbrevs: 20
Num Records: 3
Percent Abbrevs: 0.0000%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
3 60 20.0 SETBID
Block ID #8 (MODULE_BLOCK):
Num Instances: 1
Total Size: 69440b/8680.00B/2170W
Percent of file: 9.7836%
Num SubBlocks: 301
Num Abbrevs: 3
Num Records: 387
Percent Abbrevs: 0.5168%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
321 55689 173.5 FUNCTION
56 8940 159.6 GLOBALVAR
5 219 43.8 COMDAT
1 149 100.00 SOURCE_FILENAME
1 35 100.00 VSTOFFSET
1 513 DATALAYOUT
1 327 TRIPLE
1 21 VERSION
Block ID #9 (PARAMATTR_BLOCK):
Num Instances: 1
Total Size: 7637b/954.62B/238W
Percent of file: 1.0760%
Num SubBlocks: 0
Num Abbrevs: 0
Num Records: 192
Percent Abbrevs: 0.0000%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
192 7566 39.4 ENTRY
Block ID #10 (PARAMATTR_GROUP_BLOCK_ID):
Num Instances: 1
Total Size: 96949b/12118.62B/3029W
Percent of file: 13.6594%
Num SubBlocks: 0
Num Abbrevs: 0
Num Records: 168
Percent Abbrevs: 0.0000%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
168 96864 576.6 ENTRY
Block ID #11 (CONSTANTS_BLOCK):
Num Instances: 238
Total Size: 50837b/6354.62B/1588W
Percent of file: 7.1626%
Average Size: 213.60/26.70B/6W
Tot/Avg SubBlocks: 0/0.000000e+00
Tot/Avg Abbrevs: 4/1.680672e-02
Tot/Avg Records: 1826/7.672269e+00
Percent Abbrevs: 81.7634%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
823 11884 14.4 100.00 INTEGER
604 7248 12.0 100.00 SETTYPE
172 2752 16.0 NULL
78 2787 35.7 48.72 AGGREGATE
43 688 16.0 UnknownCode26
39 624 16.0 UNDEF
37 2374 64.2 CE_GEP
28 2063 73.7 96.43 CSTRING
1 1954 DATA
1 42 100.00 STRING
Block ID #12 (FUNCTION_BLOCK):
Num Instances: 291
Total Size: 255270b/31908.75B/7977W
Percent of file: 35.9657%
Average Size: 877.22/109.65B/27W
Tot/Avg SubBlocks: 269/9.243986e-01
Tot/Avg Abbrevs: 0/0.000000e+00
Tot/Avg Records: 6164/2.118213e+01
Percent Abbrevs: 42.3264%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
870 26070 30.0 INST_BR
774 18816 24.3 100.00 INST_LOAD
649 22917 35.3 100.00 INST_GEP
634 27322 43.1 INST_CMP2
527 12524 23.8 99.43 INST_BINOP
463 22546 48.7 INST_STORE
424 43408 102.4 INST_CALL
383 22394 58.5 INST_PHI
357 8452 23.7 100.00 INST_CAST
291 6402 22.0 DECLAREBLOCKS
283 2488 8.8 100.00 INST_RET
233 6530 28.0 INST_EXTRACTVAL
135 4716 34.9 INST_INSERTVAL
60 2124 35.4 INST_VSELECT
36 2004 55.7 INST_ALLOCA
22 88 4.0 100.00 INST_UNREACHABLE
15 1572 104.8 INST_SWITCH
8 224 28.0 UnknownCode58
Block ID #13 (IDENTIFICATION_BLOCK_ID):
Num Instances: 1
Total Size: 214b/26.75B/6W
Percent of file: 0.0302%
Num SubBlocks: 0
Num Abbrevs: 2
Num Records: 2
Percent Abbrevs: 100.0000%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
1 11 100.00 EPOCH
1 71 100.00 STRING
Block ID #14 (VALUE_SYMTAB):
Num Instances: 1
Total Size: 10037b/1254.62B/313W
Percent of file: 1.4141%
Num SubBlocks: 0
Num Abbrevs: 1
Num Records: 291
Percent Abbrevs: 100.0000%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
291 9924 34.1 100.00 FNENTRY
Block ID #15 (METADATA_BLOCK):
Num Instances: 1
Total Size: 917b/114.62B/28W
Percent of file: 0.1292%
Num SubBlocks: 0
Num Abbrevs: 6
Num Records: 7
Percent Abbrevs: 28.5714%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
2 50 25.0 NODE
2 68 34.0 VALUE
1 320 100.00 STRINGS
1 22 NAMED_NODE
1 90 100.00 NAME
Block ID #16 (METADATA_ATTACHMENT_BLOCK):
Num Instances: 32
Total Size: 3859b/482.38B/120W
Percent of file: 0.5437%
Average Size: 120.59/15.07B/3W
Tot/Avg SubBlocks: 0/0.000000e+00
Tot/Avg Abbrevs: 0/0.000000e+00
Tot/Avg Records: 37/1.156250e+00
Percent Abbrevs: 0.0000%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
37 1245 33.6 ATTACHMENT
Block ID #17 (TYPE_BLOCK_ID):
Num Instances: 1
Total Size: 11925b/1490.62B/372W
Percent of file: 1.6801%
Num SubBlocks: 0
Num Abbrevs: 6
Num Records: 179
Percent Abbrevs: 92.7374%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
110 4306 39.1 100.00 FUNCTION
23 492 21.4 100.00 ARRAY
17 651 38.3 100.00 STRUCT_NAMED
17 5954 350.2 76.47 STRUCT_NAME
5 122 24.4 INTEGER
2 54 27.0 100.00 STRUCT_ANON
1 4 100.00 UnknownCode25
1 16 METADATA
1 16 LABEL
1 16 VOID
1 28 NUMENTRY
Block ID #21 (OPERAND_BUNDLE_TAGS_BLOCK):
Num Instances: 1
Total Size: 1493b/186.62B/46W
Percent of file: 0.2104%
Num SubBlocks: 0
Num Abbrevs: 0
Num Records: 10
Percent Abbrevs: 0.0000%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
10 1410 141.0 OPERAND_BUNDLE_TAG
Block ID #22 (METADATA_KIND_BLOCK):
Num Instances: 1
Total Size: 6293b/786.62B/196W
Percent of file: 0.8866%
Num SubBlocks: 0
Num Abbrevs: 0
Num Records: 41
Percent Abbrevs: 0.0000%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
41 6231 152.0 KIND
Block ID #23 (STRTAB_BLOCK):
Num Instances: 1
Total Size: 119990b/14998.75B/3749W
Percent of file: 16.9057%
Num SubBlocks: 0
Num Abbrevs: 1
Num Records: 1
Percent Abbrevs: 100.0000%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
1 119883 100.00 BLOB
Block ID #25 (SYMTAB_BLOCK):
Num Instances: 1
Total Size: 73718b/9214.75B/2303W
Percent of file: 10.3863%
Num SubBlocks: 0
Num Abbrevs: 1
Num Records: 1
Percent Abbrevs: 100.0000%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
1 73611 100.00 BLOB
Block ID #26:
Num Instances: 1
Total Size: 245b/30.62B/7W
Percent of file: 0.0345%
Num SubBlocks: 0
Num Abbrevs: 0
Num Records: 2
Percent Abbrevs: 0.0000%
Record Histogram:
Count # Bits b/Rec % Abv Record Kind
2 172 86.0 UnknownCode1
in the lto step, when it pass to clang , some how the object arch is not follow the arch set by ldc2.
the clang get -Wl,-plugin-opt=mcpu=generic-rv64 -mabi=lp64d -march=rv64g
without lto it already work well.