diff --git a/compiler/pmodules.pas b/compiler/pmodules.pas
index 816c907b37..14190ee54e 100644
--- a/compiler/pmodules.pas
+++ b/compiler/pmodules.pas
@@ -2013,7 +2013,8 @@ type
          resources_used : boolean;
          program_uses_checkpointer : boolean;
          program_name : ansistring;
-         consume_semicolon_after_uses : boolean;
+         consume_semicolon_after_uses,
+         consume_semicolon_after_loaded : boolean;
          ps : tprogramparasym;
          paramnum : longint;
          textsym : ttypesym;
@@ -2030,6 +2031,8 @@ type
          init_procinfo:=nil;
          finalize_procinfo:=nil;
          resources_used:=false;
+         consume_semicolon_after_loaded:=false;
+
          { make the compiler happy and avoid an uninitialized variable warning on Setlength(sc,length(sc)+1); }
          sc:=nil;
 
@@ -2092,7 +2095,7 @@ type
                 read, all following directives are parsed as well }
               setupglobalswitches;
 
-              consume(_SEMICOLON);
+              consume_semicolon_after_loaded:=true;
 
 {$ifdef DEBUG_NODE_XML}
               XMLInitializeNodeFile('library', program_name);
@@ -2142,7 +2145,7 @@ type
                 read, all following directives are parsed as well }
               setupglobalswitches;
 
-              consume(_SEMICOLON);
+              consume_semicolon_after_loaded:=true;
 
 {$ifdef DEBUG_NODE_XML}
               XMLInitializeNodeFile('program', program_name);
@@ -2165,9 +2168,6 @@ type
            package or not }
          load_packages;
 
-         { global switches are read, so further changes aren't allowed }
-         current_module.in_global:=false;
-
          { set implementation flag }
          current_module.in_interface:=false;
          current_module.interface_compiled:=true;
@@ -2179,6 +2179,13 @@ type
          { load system unit }
          loadsystemunit;
 
+         { consume the semicolon now that the system unit is loaded }
+         if consume_semicolon_after_loaded then
+           consume(_SEMICOLON);
+
+         { global switches are read, so further changes aren't allowed }
+         current_module.in_global:=false;
+  
          { system unit is loaded, now insert feature defines }
          for feature:=low(tfeature) to high(tfeature) do
            if feature in features then