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.
This commit is contained in:
Stephen Heumann 2022-02-06 21:49:08 -06:00
parent 9cdf199c3a
commit bd811559d6
4 changed files with 19 additions and 6 deletions

View File

@ -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}

View File

@ -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

View File

@ -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}

View File

@ -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.