LDC with MSP430

Luís Marques via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Mon Jun 19 18:51:14 PDT 2017


Hello,

In the past I used LDC for bare metal programming of a RISC-V, 
simply by tweaking the white list of accepted architectures. I 
tried to do the same for the MSP430, but in this case it seems 
some other things will have to be tweaked. This might be 
something easy for someone more familiar with the LDC/LLVM 
codebase, so could anyone give a helping hand here?

The issue so far seems to be that LDC gets confused about the 
data type sizes, probably because the MSP430 has a 16-bit CPU 
core (C ints are 16 bit):

```
Assertion failed: (llSize <= dSize && "LLVM type is bigger than 
the corresponding D type, " "might lead to aggregate layout 
mismatch."), function getMemberSize, file ../gen/llvmhelpers.cpp, 
line 1351.
0  ldc2                     0x00000001034bbc9c 
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1  ldc2                     0x00000001034bc1e9 
PrintStackTraceSignalHandler(void*) + 25
2  ldc2                     0x00000001034b8139 
llvm::sys::RunSignalHandlers() + 425
3  ldc2                     0x00000001034bc642 SignalHandler(int) 
+ 354
4  libsystem_platform.dylib 0x00007fffcee36b3a _sigtramp + 26
5  ldc2                     0x000000010396ce00 cppmain(int, 
char**)::DL + 48
6  libsystem_c.dylib        0x00007fffcecbb420 abort + 129
7  libsystem_c.dylib        0x00007fffcec82893 basename_r + 0
8  ldc2                     0x000000010145dbbf 
getMemberSize(Type*) + 175
9  ldc2                     0x000000010154ddc8 
AggrTypeBuilder::addAggregate(AggregateDeclaration*, 
std::__1::map<VarDeclaration*, llvm::Constant*, 
std::__1::less<VarDeclaration*>, 
std::__1::allocator<std::__1::pair<VarDeclaration* const, 
llvm::Constant*> > > const*, AggrTypeBuilder::Aliases) + 2824
10 ldc2                     0x000000010154d2b6 
AggrTypeBuilder::addAggregate(AggregateDeclaration*) + 38
11 ldc2                     0x000000010155199e 
IrTypeClass::addClassData(AggrTypeBuilder&, ClassDeclaration*) + 
414
12 ldc2                     0x00000001015520f4 
IrTypeClass::get(ClassDeclaration*) + 612
13 ldc2                     0x000000010150ae3e DtoType(Type*) + 
958
14 ldc2                     0x0000000101549d0e 
IrFuncTyArg::IrFuncTyArg(Type*, bool, AttrBuilder) + 126
15 ldc2                     0x0000000101549dbc 
IrFuncTyArg::IrFuncTyArg(Type*, bool, AttrBuilder) + 44
16 ldc2                     0x000000010143eb3c 
DtoFunctionType(Type*, IrFuncTy&, Type*, Type*, bool, bool, bool, 
bool) + 3468
17 ldc2                     0x00000001015552ac 
IrTypeFunction::get(Type*) + 220
18 ldc2                     0x000000010150ae6e DtoType(Type*) + 
1006
19 ldc2                     0x00000001014c6ce5 
createFwdDecl(LINK, Type*, llvm::ArrayRef<llvm::StringRef>, 
llvm::ArrayRef<Type*>, llvm::ArrayRef<unsigned long>, AttrSet) + 
373
20 ldc2                     0x00000001014b708f 
buildRuntimeModule() + 9327
21 ldc2                     0x00000001014b4c02 initRuntime() + 50
22 ldc2                     0x0000000101473178 
codegenModule(IRState*, Module*) + 248
23 ldc2                     0x000000010158a3ac 
ldc::CodeGenerator::emit(Module*) + 300
24 ldc2                     0x00000001015d8e4e 
codegenModules(Array<Module*>&) + 574
25 ldc2                     0x00000001012949c0 
mars_mainBody(Array<char const*>&, Array<char const*>&) + 5120
```

(BTW, I used -mtriple=msp430, since `msp430-gcc -dumpmachine` 
gives out that "triple")


More information about the digitalmars-d-ldc mailing list