From bd811559d6f67d16cf3fcccd2cebadbfd57e193b Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 6 Feb 2022 21:49:08 -0600 Subject: [PATCH] Fix issues with keep names in sym files. There were a couple issues that could occur with #pragma keep and sym files: *If a source file used #pragma keep but it was overridden by KEEP= on the command line or {KeepName} in the shell, then the overriding keep name would be saved to the sym file. It would therefore be applied to subsequent compilations even if it was no longer specified in the command line or shell variable. *If a source file used #pragma keep, that keep name would be recorded in the sym file. On subsequent compilations, it would always be used, overriding any keep name specified by the command line or shell, contrary to the usual rule that the name on the command line takes priority. With this patch, the keep name recorded in the sym file (if any) should always be the one specified by #pragma keep, but it can be overridden as usual. --- CCommon.pas | 1 + Header.pas | 12 +++++++----- Scanner.pas | 10 +++++++++- cc.notes | 2 ++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CCommon.pas b/CCommon.pas index cb1974c..40f01f8 100644 --- a/CCommon.pas +++ b/CCommon.pas @@ -498,6 +498,7 @@ var oldincludeFileGS: gsosOutString; {previous includeFile value} outFileGS: gsosOutString; {keep file name} partialFileGS: gsosOutString; {partial compile list} + pragmaKeepFile: gsosOutStringPtr; {filename specified in #pragma keep} sourceFileGS: gsosOutString; {presumed source file name} tempList: tempPtr; {list of temp work variables} longlong0: longlong; {the value 0 as a longlong} diff --git a/Header.pas b/Header.pas index 494dc27..ad7c061 100644 --- a/Header.pas +++ b/Header.pas @@ -798,7 +798,7 @@ procedure EndInclude {chPtr: ptr}; WriteWord(floatSlot); end; - p_keep: WriteLongString(@outFileGS.theString); + p_keep: WriteLongString(@pragmaKeepFile^.theString); p_line: begin WriteWord(lineNumber); @@ -1444,11 +1444,13 @@ var end; p_keep: begin - liDCBGS.kFlag := 1; lsPtr := ReadLongString; - outFileGS.theString.size := lsPtr^.length; - for i := 1 to outFileGS.theString.size do - outFileGS.theString.theString[i] := lsPtr^.str[i]; + if liDCBGS.kFlag = 0 then begin + liDCBGS.kFlag := 1; + outFileGS.theString.size := lsPtr^.length; + for i := 1 to outFileGS.theString.size do + outFileGS.theString.theString[i] := lsPtr^.str[i]; + end; {if} end; p_line: begin diff --git a/Scanner.pas b/Scanner.pas index 42fa95e..c7004a1 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -2776,8 +2776,15 @@ var { #pragma keep FILENAME } begin {DoKeep} - FlagPragmas(p_keep); if GetFileName(false) then begin {read the file name} + FlagPragmas(p_keep); + if not ignoreSymbols then + if pragmaKeepFile = nil then begin + new(pragmaKeepFile); + pragmaKeepFile^.maxSize := maxPath + 4; + pragmaKeepFile^.theString.theString := workString; + pragmaKeepFile^.theString.size := length(workString); + end; {if} if foundFunction then Error(17); if liDCBGS.kFlag = 0 then begin {use the old name if there is one...} @@ -4105,6 +4112,7 @@ lintIsError := true; {lint messages are considered errors} fenvAccess := false; {not accessing fp environment} charStrPrefix := prefix_none; {no char/str prefix seen} mergingStrings := false; {not currently merging strings} +pragmaKeepFile := nil; {no #pragma keep file so far} {error codes for lint messages} {if changed, also change maxLint} diff --git a/cc.notes b/cc.notes index f917767..3d31663 100644 --- a/cc.notes +++ b/cc.notes @@ -1746,6 +1746,8 @@ int foo(int[42]); 177. The name of the current source file was not updated when processing an #include or #append. As a result, uses of the __FILE__ macro within an include file would not give the name of that file, and functions (or portions of functions) within an include file would not have the proper file name recorded in their debugging information. +178. Keep names specified via the KEEP= portion of the command line or the {KeepName} shell variable could sometimes be saved in the .sym file and applied to subsequent compilations, even if they were no longer specified for the later compilation. Also, if a .sym file was used, the keep name specified via #pragma keep might override the one specified on the command line or via {KeepName}. + -- Bugs from C 2.1.0 that have been fixed ----------------------------------- 1. In some situations, fread() reread the first 1K or so of the file.