On Monday, 4 December 2017 at 00:25:53 UTC, Michael V. Franklin
wrote:
A better solution would be to do what Iain said:
Try compiling a simple "hello world" with an empty object.d
file. Then inspect what the compiler does. Does it error and
exit, or does it ICE? What can be done to prevent that from
happening?
When you reach the point that there's no way but to declare a
symbol or function, add that to object.d and then move onto
the next error or ICE. Repeat until you can compile and link
your program.
Next, try something a little more complex, such as define a
struct and use it. Then again address all problems that you
encounter with that.
Here's an illustration:
object.d
----------------------------
module object;
alias immutable(char)[] string;
struct ModuleInfo { }
main.d
-----------------------------
module main;
long sys_write(long arg1, in void* arg2, long arg3)
{
long result;
asm
{
mov RAX, 1;
mov RDI, arg1;
mov RSI, arg2;
mov RDX, arg3;
syscall;
}
return result;
}
void write(in string text)
{
sys_write(2, text.ptr, text.length);
}
extern(C) void main()
{
write("Hello\n");
}
.$> dmd -defaultlib= -debuglib= -conf= main.d -of=main
/usr/bin/ld: main.o: relocation R_X86_64_32 against
`.rodata.str1.1' can not be used when making a shared object;
recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
I didn't compile with -shared. What's going on here?
.$> dmd -defaultlib= -debuglib= -conf= main.d -of=main -fPIC
main.o:(.text.d_dso_init[.data.d_dso_rec]+0x22): undefined
reference to `_d_dso_registry'
Again, not sure why the compiler's generated code for that?
Would it help for me to file bugzilla issues for things like
this? The reason I haven't thus far, is that this is just a
symptom of a larger issue. It needs a development strategy to be
solved holistically.
Mike