Back to docs

So What Happened?

A programmer-level look at the glibc errors in the Linux ports of the Kenta Cho games in D. (A7Xpg, Area 2028, Parsec 47, Torus Troopers, and Tumiki Fighters)

The symptoms:

Although the executable in each of these programs worked on my computer, a large number of people were getting the error "./ttrooper: relocation error: ./ttrooper: symbol __libc_stack_end, version GLIBC_PRIVATE not defined in file with link time reference", or similar errors in the other programs. Recompiling would fix the problem on that computer, but needed some measure of technical skill.

The cause:

This was actually a compiler bug. I first realized this while trying to create a statically-compiled binary using autopackage, after talking to the forums there. While the D compiler itself is not open source, the Phobos runtime library is, and so I was able to fix the bug.
The problem was the line:
void* __libc_stack_end;
in std/c/linux/linuxextern.d. That variable was linked to my version of __libc_stack_end in glibc, which doesn't work if someone has a different version of glibc. To fix, I commented out that line, and replaced os_query_stackBottom() in internal/gc/gclinux.d with:
void **libc_stack_end;
void *os_query_stackBottom()
	if(libc_stack_end != libc_stack_end.init)
		return *libc_stack_end;
	HModule_    handle;
	handle = dlopen(cast(char *)0, RTLD_NOW);
	libc_stack_end = cast(void **)dlsym(handle, "__libc_stack_end");
	return *libc_stack_end;

Finally, I linked the __libc_stack_end reference in std/thread.d to this, and everything worked; people were able to use my compiled binaries.


I sent this code to Digital Mars, and am working on getting it folded into their compiler. As Kenta Cho's games only compile in version 0.106 or earlier of the compiler, I'll keep using my hacked-up version, but this could help others.

Thanks to:

mike from the autopackage forums, for pointing me in the right direction.
Leagalizer from email correspondence, for testing all the versions that didn't quite work.