about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--subx/035labels.cc12
-rw-r--r--subx/036global_variables.cc14
2 files changed, 26 insertions, 0 deletions
diff --git a/subx/035labels.cc b/subx/035labels.cc
index acbb2206..5531910a 100644
--- a/subx/035labels.cc
+++ b/subx/035labels.cc
@@ -125,6 +125,10 @@ void compute_byte_indices_for_labels(const segment& code, map<string, int32_t>&
           raise << "'" << to_string(inst) << "': labels can only be the first word in a line.\n" << end();
         if (Map_file.is_open())
           Map_file << "0x" << HEXWORD << (code.start + current_byte) << ' ' << label << '\n';
+        if (contains_key(byte_index, label)) {
+          raise << "duplicate label '" << label << "'\n" << end();
+          return;
+        }
         put(byte_index, label, current_byte);
         trace(99, "transform") << "label '" << label << "' is at address " << (current_byte+code.start) << end();
         // no modifying current_byte; label definitions won't be in the final binary
@@ -237,6 +241,14 @@ loop:
 # second jump is to 0 (fall through)
 +transform: instruction after transform: 'eb 00'
 
+:(scenario duplicate_label)
+% Hide_errors = true;
+== 0x1
+loop:
+loop:
+    05  0x0d0c0b0a/imm32
++error: duplicate label 'loop'
+
 :(scenario label_too_short)
 % Hide_errors = true;
 == 0x1
diff --git a/subx/036global_variables.cc b/subx/036global_variables.cc
index afeb7427..5c707bd3 100644
--- a/subx/036global_variables.cc
+++ b/subx/036global_variables.cc
@@ -49,6 +49,10 @@ void compute_addresses_for_global_variables(const segment& s, map<string, uint32
           raise << "'" << to_string(inst) << "': global variable names can only be the first word in a line.\n" << end();
         if (Map_file.is_open())
           Map_file << "0x" << HEXWORD << current_address << ' ' << variable << '\n';
+        if (contains_key(address, variable)) {
+          raise << "duplicate global '" << variable << "'\n" << end();
+          return;
+        }
         put(address, variable, current_address);
         trace(99, "transform") << "global variable '" << variable << "' is at address 0x" << HEXWORD << current_address << end();
         // no modifying current_address; global variable definitions won't be in the final binary
@@ -188,6 +192,16 @@ y:
 +load: 0x0a000003 -> 0a
 $error: 0
 
+:(scenario duplicate_global_variable)
+% Hide_errors = true;
+== 0x1
+40/increment-EAX
+== 0x0a000000
+x:
+x:
+  00
++error: duplicate global 'x'
+
 :(scenario disp32_data_with_modrm)
 == code
 8b/copy 0/mod/indirect 5/rm32/.disp32 2/r32/EDX x/disp32