changeset 523:1744f2d1a821

Change behaviour of --format=raw; old behaviour kept for --format=raw2 Make the default --format=raw output just ignore BSS flagged sections. If you put any in the middle of your code, your output file will break. Don't do dumb things like that. If you really need the old behaviour, change to --format=raw2 Neither behaviour is really ideal but doing the "right" thing is a boatload more complicated and is still going to do the wrong thing from time to time. Most situations will likely load the BSS sections with separate link script directives anyway or be assembling directly to raw without using the linker.
author William Astle <lost@l-w.ca>
date Mon, 24 Jan 2022 13:55:40 -0700
parents 01bdad2118aa
children a4a58c4c7a41
files lwlink/lwlink.h lwlink/main.c lwlink/output.c
diffstat 3 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lwlink/lwlink.h	Sun Jan 02 00:59:21 2022 -0700
+++ b/lwlink/lwlink.h	Mon Jan 24 13:55:40 2022 -0700
@@ -27,10 +27,11 @@
 #include "expr.h"
 
 #define OUTPUT_DECB		0	// DECB multirecord format
-#define OUTPUT_RAW		1	// raw sequence of bytes
+#define OUTPUT_RAW		1	// raw sequence of bytes; BSS is just not included
 #define OUTPUT_LWEX0	2	// LWOS LWEX binary version 0
 #define OUTPUT_OS9		3	// OS9 object code module
 #define OUTPUT_SREC		4	// motorola SREC format
+#define OUTPUT_RAW2     5   // raw sequence of bytes, BSS converted to NULs
 
 typedef struct symtab_s symtab_t;
 struct symtab_s
--- a/lwlink/main.c	Sun Jan 02 00:59:21 2022 -0700
+++ b/lwlink/main.c	Mon Jan 24 13:55:40 2022 -0700
@@ -84,6 +84,8 @@
 			outformat = OUTPUT_DECB;
 		else if (!strcasecmp(arg, "raw"))
 			outformat = OUTPUT_RAW;
+		else if (!strcasecmp(arg, "raw2"))
+			outformat = OUTPUT_RAW2;
 		else if (!strcasecmp(arg, "lwex0") || !strcasecmp(arg, "lwex"))
 			outformat = OUTPUT_LWEX0;
 		else if (!strcasecmp(arg, "os9"))
--- a/lwlink/output.c	Sun Jan 02 00:59:21 2022 -0700
+++ b/lwlink/output.c	Mon Jan 24 13:55:40 2022 -0700
@@ -36,6 +36,7 @@
 void do_output_os9(FILE *of);
 void do_output_decb(FILE *of);
 void do_output_raw(FILE *of);
+void do_output_raw2(FILE *of);
 void do_output_lwex0(FILE *of);
 void do_output_srec(FILE *of);
 
@@ -61,6 +62,10 @@
 		do_output_raw(of);
 		break;
 
+	case OUTPUT_RAW2:
+		do_output_raw2(of);
+		break;
+
 	case OUTPUT_LWEX0:
 		do_output_lwex0(of);
 		break;
@@ -145,8 +150,25 @@
 
 void do_output_raw(FILE *of)
 {
+	int sn;
+
+	
+	for (sn = 0; sn < nsects; sn++)
+	{
+		if (sectlist[sn].ptr -> flags & SECTION_BSS)
+		{
+			// no output for a BSS section
+			continue;
+		}
+		writebytes(sectlist[sn].ptr -> code, 1, sectlist[sn].ptr -> codesize, of);
+	}
+}
+
+void do_output_raw2(FILE *of)
+{
 	int nskips = 0;		// used to output blanks for BSS inline
 	int sn;
+
 	
 	for (sn = 0; sn < nsects; sn++)
 	{