View Issue Details

IDProjectCategoryView StatusLast Update
0036562FPCCompilerpublic2020-01-13 07:32
ReporterChristo CrauseAssigned ToFlorian 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.3.1Product Build43920 
Target VersionFixed in Version3.3.1 
Summary0036562: [patch] Passing a file name with extension to cross compiler with -o causes error
DescriptionWhen passing an executable name such as project1.elf to an embedded compiler with the -o option, it results in an error: "Can't open executable project1.elf.elf"

The error seem to be caused by appending .elf to the exe file name when calling PostProcessExecutable in TlinkerEmbedded.MakeExecutable.

Attached a patch which fixes the inconsistent exe file name in MakeExecutable. Since the exe file name is used in several places, I created a new variable FixedExeFileName where the file extension is changed properly. This variable is then used throughout this procedure to ensure consistency in the file name.
TagsNo tags attached.
Fixed in Revision43921
FPCOldBugId
FPCTarget-
Attached Files
  • fixexeext.patch (2,533 bytes)
    Index: compiler/systems/t_embed.pas
    ===================================================================
    --- compiler/systems/t_embed.pas	(revision 43920)
    +++ compiler/systems/t_embed.pas	(working copy)
    @@ -1260,7 +1260,8 @@
       StaticStr,
       GCSectionsStr,
       DynLinkStr,
    -  StripStr: string;
    +  StripStr,
    +  FixedExeFileName: string;
     begin
       { for future use }
       StaticStr:='';
    @@ -1267,6 +1268,7 @@
       StripStr:='';
       mapstr:='';
       DynLinkStr:='';
    +  FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')));
     
       GCSectionsStr:='--gc-sections';
       //if not(cs_link_extern in current_settings.globalswitches) then
    @@ -1284,7 +1286,7 @@
       Replace(cmdstr,'$OPT',Info.ExtraOptions);
       if not(cs_link_on_target in current_settings.globalswitches) then
        begin
    -    Replace(cmdstr,'$EXE',(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')))));
    +    Replace(cmdstr,'$EXE',FixedExeFileName);
         Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
         Replace(cmdstr,'$STATIC',StaticStr);
         Replace(cmdstr,'$STRIP',StripStr);
    @@ -1294,7 +1296,7 @@
        end
       else
        begin
    -    Replace(cmdstr,'$EXE',maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf'))));
    +    Replace(cmdstr,'$EXE',FixedExeFileName);
         Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
         Replace(cmdstr,'$STATIC',StaticStr);
         Replace(cmdstr,'$STRIP',StripStr);
    @@ -1310,16 +1312,16 @@
     
     { Post process }
       if success and not(cs_link_nolink in current_settings.globalswitches) then
    -    success:=PostProcessExecutable(current_module.exefilename+'.elf',false);
    +    success:=PostProcessExecutable(FixedExeFileName,false);
     
       if success and (target_info.system in [system_arm_embedded,system_avr_embedded,system_mipsel_embedded]) then
         begin
           success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
    -        maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')))+' '+
    +        FixedExeFileName+' '+
             maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.hex'))),true,false);
           if success then
             success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
    -          maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')))+' '+
    +          FixedExeFileName+' '+
               maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
         end;
     
    
    fixexeext.patch (2,533 bytes)

Activities

Christo Crause

2020-01-12 14:48

reporter  

fixexeext.patch (2,533 bytes)
Index: compiler/systems/t_embed.pas
===================================================================
--- compiler/systems/t_embed.pas	(revision 43920)
+++ compiler/systems/t_embed.pas	(working copy)
@@ -1260,7 +1260,8 @@
   StaticStr,
   GCSectionsStr,
   DynLinkStr,
-  StripStr: string;
+  StripStr,
+  FixedExeFileName: string;
 begin
   { for future use }
   StaticStr:='';
@@ -1267,6 +1268,7 @@
   StripStr:='';
   mapstr:='';
   DynLinkStr:='';
+  FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')));
 
   GCSectionsStr:='--gc-sections';
   //if not(cs_link_extern in current_settings.globalswitches) then
@@ -1284,7 +1286,7 @@
   Replace(cmdstr,'$OPT',Info.ExtraOptions);
   if not(cs_link_on_target in current_settings.globalswitches) then
    begin
-    Replace(cmdstr,'$EXE',(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')))));
+    Replace(cmdstr,'$EXE',FixedExeFileName);
     Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
     Replace(cmdstr,'$STATIC',StaticStr);
     Replace(cmdstr,'$STRIP',StripStr);
@@ -1294,7 +1296,7 @@
    end
   else
    begin
-    Replace(cmdstr,'$EXE',maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf'))));
+    Replace(cmdstr,'$EXE',FixedExeFileName);
     Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
     Replace(cmdstr,'$STATIC',StaticStr);
     Replace(cmdstr,'$STRIP',StripStr);
@@ -1310,16 +1312,16 @@
 
 { Post process }
   if success and not(cs_link_nolink in current_settings.globalswitches) then
-    success:=PostProcessExecutable(current_module.exefilename+'.elf',false);
+    success:=PostProcessExecutable(FixedExeFileName,false);
 
   if success and (target_info.system in [system_arm_embedded,system_avr_embedded,system_mipsel_embedded]) then
     begin
       success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
-        maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')))+' '+
+        FixedExeFileName+' '+
         maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.hex'))),true,false);
       if success then
         success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
-          maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')))+' '+
+          FixedExeFileName+' '+
           maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
     end;
 
fixexeext.patch (2,533 bytes)

Christo Crause

2020-01-12 14:53

reporter   ~0120362

Note that this issue is related to improving embedded support in Lazarus, see issue 0036561

Florian

2020-01-12 21:58

administrator   ~0120380

Thanks, applied.

Christo Crause

2020-01-13 07:32

reporter   ~0120393

Thank you Florian. I hope this patch gets pushed to the fixes branch so that it is available for the next Lazarus release :-)

Issue History

Date Modified Username Field Change
2020-01-12 14:48 Christo Crause New Issue
2020-01-12 14:48 Christo Crause File Added: fixexeext.patch
2020-01-12 14:53 Christo Crause Note Added: 0120362
2020-01-12 21:58 Florian Assigned To => Florian
2020-01-12 21:58 Florian Status new => resolved
2020-01-12 21:58 Florian Resolution open => fixed
2020-01-12 21:58 Florian Fixed in Version => 3.3.1
2020-01-12 21:58 Florian Fixed in Revision => 43921
2020-01-12 21:58 Florian FPCTarget => -
2020-01-12 21:58 Florian Note Added: 0120380
2020-01-13 07:32 Christo Crause Status resolved => closed
2020-01-13 07:32 Christo Crause Note Added: 0120393