shithub: mc

Download patch

ref: e3068fa21bebe67d64694e91497e0c02ee39d293
parent: f15de4539efb079f7c27ceb1daf4858a347ac832
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Sep 24 09:42:28 EDT 2014

Work around compiler bug.

    Seems we don't get the offsets right when we have holes
    during matching structs in match statements. Alignment problems?

--- a/build.myr
+++ b/build.myr
@@ -10,7 +10,7 @@
 	const buildall	: (p : parser# -> bool)
 	const test	: (p : parser# -> bool)
 	const build	: (p : parser#, target : byte[:] -> bool)
-	const buildbin	: (bin : byte[:], inputs : byte[:][:], ldscript : byte[:] -> void)
+	const buildbin	: (bin : byte[:], inputs : byte[:][:], ldscript : byte[:], rt : byte[:] -> void)
 	const buildlib	: (lib : byte[:], inputs : byte[:][:] -> void)
 ;;
 
@@ -17,8 +17,8 @@
 const buildall = {p
 	for t in p.targs
 		match t
-		| `Bin [.name=bin, .inputs=leaves, .ldscript=ldscript]:
-			buildbin(bin, leaves, ldscript)
+		| `Bin [.name=bin, .inputs=leaves, .install=_, .ldscript=lds, .runtime=rt]:
+			buildbin(bin, leaves, lds, rt)
 		| `Lib [.name=lib, .inputs=leaves]:
 			buildlib(lib, leaves)
 		| `Sub subs:
@@ -43,9 +43,9 @@
 	built = false
 	for t in p.targs
 		match t
-		| `Bin [.name=bin, .inputs=leaves, .ldscript=ldscript]:
+		| `Bin [.name=bin, .inputs=leaves, .install=_, .ldscript=lds, .runtime=rt]:
 			if std.sleq(bin, targ)
-				buildbin(bin, leaves, ldscript)
+				buildbin(bin, leaves, lds, rt)
 				built = true
 			;;
 		| `Lib [.name=lib, .inputs=leaves]:
@@ -70,7 +70,7 @@
 	-> built
 }
 
-const buildbin = {bin, inputs, ldscript
+const buildbin = {bin, inputs, ldscript, rt
 	var dg
 
 	std.put("LD SCRIPT: %s\n", ldscript)
@@ -82,7 +82,7 @@
 		for d in deps
 			builddep(&dg, d, bin)
 		;;
-		linkbin(&dg, bin, inputs, ldscript)
+		linkbin(&dg, bin, inputs, ldscript, rt)
 	| `std.None:
 		std.fatal(1, "No such binary %s\n", bin)
 	;;
@@ -126,7 +126,7 @@
 	;;
 }
 
-const linkbin = {dg, bin, srcfiles, ldscript
+const linkbin = {dg, bin, srcfiles, ldscript, rt
 	var cmd
 	var obj
 
@@ -138,13 +138,17 @@
 	cmd = std.slpush(cmd, std.sldup(bin))
 
 	/* [-T script] */
-	std.put("ldscript = %s\n")
+	std.put("ldscript = %s\n", ldscript)
 	if ldscript.len > 0
 		cmd = std.slpush(cmd, std.sldup("-T"))
 		cmd = std.slpush(cmd, std.sldup(ldscript))
 	;;
 
-	cmd = std.slpush(cmd, std.fmt("%s/%s", opt_instroot, "/lib/myr/_myrrt.o"))
+	if rt.len != 0
+		cmd = std.slpush(cmd, std.sldup(rt))
+	else
+		cmd = std.slpush(cmd, std.fmt("%s/%s", opt_instroot, "/lib/myr/_myrrt.o"))
+	;;
 
 	/* input.o list.o... */
 	for f in srcfiles
--- a/config.myr
+++ b/config.myr
@@ -1,4 +1,4 @@
 pkg config = 
-const Instroot = "/Users/orib/bin"
-const Sys = "OSX"
+const Instroot = "/usr/local/google/home/orib/bin"
+const Sys = "Linux"
 ;;
--- a/parse.myr
+++ b/parse.myr
@@ -74,6 +74,10 @@
 
 const bintarget = {p
 	p.targs = std.slpush(p.targs, `Bin myrtarget(p, "bin"))
+	match p.targs[p.targs.len - 1]
+	| `Bin b:
+		std.put("ldscript in targ = %s\n", b.ldscript)
+	;;
 }
 
 const libtarget = {p
@@ -103,6 +107,8 @@
 		| `std.Some al:	attrs = al
 		| `std.None:	failparse(p, "invalid attr list for %s %s", targ, name)
 		;;
+	else
+		attrs = [][:]
 	;;
 
 	skipspace(p)
@@ -118,10 +124,15 @@
 	if !matchc(p, ';')
 		failparse(p, "expected ';' terminating input list, got %c\n", peekc(p))
 	;;
+
 	inst = true
+	ldscript = ""
+	runtime = ""
 	for elt in attrs
 		match elt
-		| ("ldscript", lds):	ldscript = std.sldup(lds)
+		| ("ldscript", lds):
+			std.put("ldscript attr = %s\n", lds)
+			ldscript = std.sldup(lds)
 		| ("runtime", rt):	runtime = std.sldup(rt)
 		| ("noinst", val):
 			if val.len != 0
@@ -130,10 +141,10 @@
 			inst = false
 		;;
 	;;
-	std.slfree(attrs)
+	std.put("ldscript = %s\n", ldscript)
 	-> [
 		.name=name,
-		.inputs=inputs, 
+		.inputs=inputs,
 		.install=inst,
 		.ldscript=ldscript,
 		.runtime=runtime