Browse Source

* fixed handling of paths/files with spaces in their name in link.res
on platforms where the `cat link.res` trick is used. Those must
/not/ be quoted, because otherwise the shell assumes those quotes
are part of the filename, and will escape the quotes themselves.

Instead, write everything out without quotes, but set IFS to
<newline> before doing the cat, so that only a new line is seen
as a separator between items. The shell will then insert the
necessary quotes to escape the spaces. One disadvantage: this
means that other options, such as e.g. "-arch ppc" under Darwin,
must now be written split over two lines to avoid the shell
passing such parameters (which consist of two separate strings)
as one single parameter (with an escaped space) to ld.

git-svn-id: trunk@8166 -

Jonas Maebe 18 years ago
parent
commit
9c69c9dcf8
3 changed files with 37 additions and 17 deletions
  1. 4 0
      compiler/script.pas
  2. 8 5
      compiler/systems/t_beos.pas
  3. 25 12
      compiler/systems/t_bsd.pas

+ 4 - 0
compiler/script.pas

@@ -378,7 +378,11 @@ Procedure TAsmScriptUnix.AddLinkCommand (Const Command, Options, FileName : TCmd
 begin
 begin
   if FileName<>'' then
   if FileName<>'' then
    Add('echo Linking '+ScriptFixFileName(FileName));
    Add('echo Linking '+ScriptFixFileName(FileName));
+  Add('OFS=$IFS');
+  Add('IFS="');
+  Add('"');
   Add(maybequoted(command)+' '+Options);
   Add(maybequoted(command)+' '+Options);
+  Add('IFS=$OFS');
   Add('if [ $? != 0 ]; then DoExitLink '+ScriptFixFileName(FileName)+'; fi');
   Add('if [ $? != 0 ]; then DoExitLink '+ScriptFixFileName(FileName)+'; fi');
 end;
 end;
 
 

+ 8 - 5
compiler/systems/t_beos.pas

@@ -247,19 +247,22 @@ begin
   else
   else
    LinkRes.Add('ld -o $1 -e 0 $2 $3 $4 $5 $6 $7 $8 $9\');
    LinkRes.Add('ld -o $1 -e 0 $2 $3 $4 $5 $6 $7 $8 $9\');
   }
   }
-  LinkRes.Add('-m elf_i386_be -shared -Bsymbolic');
+  LinkRes.Add('-m');
+  LinkRes.Add('elf_i386_be');
+  LinkRes.Add('-shared');
+  LinkRes.Add('-Bsymbolic');
 
 
   { Write path to search libraries }
   { Write path to search libraries }
   HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
   HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
   while assigned(HPath) do
   while assigned(HPath) do
    begin
    begin
-     LinkRes.Add(maybequoted('-L'+HPath.Str));
+     LinkRes.Add('-L'+HPath.Str);
      HPath:=TCmdStrListItem(HPath.Next);
      HPath:=TCmdStrListItem(HPath.Next);
    end;
    end;
   HPath:=TCmdStrListItem(LibrarySearchPath.First);
   HPath:=TCmdStrListItem(LibrarySearchPath.First);
   while assigned(HPath) do
   while assigned(HPath) do
    begin
    begin
-     LinkRes.Add(maybequoted('-L'+HPath.Str));
+     LinkRes.Add('-L'+HPath.Str);
      HPath:=TCmdStrListItem(HPath.Next);
      HPath:=TCmdStrListItem(HPath.Next);
    end;
    end;
 
 
@@ -293,7 +296,7 @@ begin
    begin
    begin
      s:=ObjectFiles.GetFirst;
      s:=ObjectFiles.GetFirst;
      if s<>'' then
      if s<>'' then
-      LinkRes.AddFileName(maybequoted(s));
+      LinkRes.AddFileName(s);
    end;
    end;
 
 
 {  LinkRes.Add('-lroot \');
 {  LinkRes.Add('-lroot \');
@@ -306,7 +309,7 @@ begin
      While not StaticLibFiles.Empty do
      While not StaticLibFiles.Empty do
       begin
       begin
         S:=StaticLibFiles.GetFirst;
         S:=StaticLibFiles.GetFirst;
-        LinkRes.AddFileName(maybequoted(s))
+        LinkRes.AddFileName(s)
       end;
       end;
    end;
    end;
 
 

+ 25 - 12
compiler/systems/t_bsd.pas

@@ -366,15 +366,16 @@ begin
 
 
   if (not isdll) then
   if (not isdll) then
     begin
     begin
+      LinkRes.Add('-arch');
       case target_info.system of
       case target_info.system of
         system_powerpc_darwin:
         system_powerpc_darwin:
-           LinkRes.Add('-arch ppc');
+           LinkRes.Add('ppc');
         system_i386_darwin:
         system_i386_darwin:
-           LinkRes.Add('-arch i386');
+           LinkRes.Add('i386');
         system_powerpc64_darwin:
         system_powerpc64_darwin:
-           LinkRes.Add('-arch ppc64');
+           LinkRes.Add('ppc64');
         system_x86_64_darwin:
         system_x86_64_darwin:
-           LinkRes.Add('-arch x86_64');
+           LinkRes.Add('x86_64');
       end;
       end;
   end;
   end;
   { Write path to search libraries }
   { Write path to search libraries }
@@ -382,7 +383,7 @@ begin
   while assigned(HPath) do
   while assigned(HPath) do
    begin
    begin
      if LdSupportsNoResponseFile then
      if LdSupportsNoResponseFile then
-       LinkRes.Add(maybequoted('-L'+HPath.Str))
+       LinkRes.Add('-L'+HPath.Str)
      else
      else
        LinkRes.Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
        LinkRes.Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
      HPath:=TCmdStrListItem(HPath.Next);
      HPath:=TCmdStrListItem(HPath.Next);
@@ -391,7 +392,7 @@ begin
   while assigned(HPath) do
   while assigned(HPath) do
    begin
    begin
      if LdSupportsNoResponseFile then
      if LdSupportsNoResponseFile then
-       LinkRes.Add(maybequoted('-L'+HPath.Str))
+       LinkRes.Add('-L'+HPath.Str)
      else
      else
        LinkRes.Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
        LinkRes.Add('SEARCH_DIR('+maybequoted(HPath.Str)+')');
      HPath:=TCmdStrListItem(HPath.Next);
      HPath:=TCmdStrListItem(HPath.Next);
@@ -402,13 +403,13 @@ begin
       HPath:=TCmdStrListItem(current_module.localframeworksearchpath.First);
       HPath:=TCmdStrListItem(current_module.localframeworksearchpath.First);
       while assigned(HPath) do
       while assigned(HPath) do
        begin
        begin
-         LinkRes.Add(maybequoted('-F'+HPath.Str));
+         LinkRes.Add('-F'+HPath.Str);
          HPath:=TCmdStrListItem(HPath.Next);
          HPath:=TCmdStrListItem(HPath.Next);
        end;
        end;
       HPath:=TCmdStrListItem(FrameworkSearchPath.First);
       HPath:=TCmdStrListItem(FrameworkSearchPath.First);
       while assigned(HPath) do
       while assigned(HPath) do
        begin
        begin
-         LinkRes.Add(maybequoted('-F'+HPath.Str));
+         LinkRes.Add('-F'+HPath.Str);
          HPath:=TCmdStrListItem(HPath.Next);
          HPath:=TCmdStrListItem(HPath.Next);
        end;
        end;
     end;
     end;
@@ -432,7 +433,10 @@ begin
    begin
    begin
      s:=ObjectFiles.GetFirst;
      s:=ObjectFiles.GetFirst;
      if s<>'' then
      if s<>'' then
-      LinkRes.AddFileName(maybequoted(s));
+      if LdSupportsNoResponseFile then
+        LinkRes.AddFileName(s)
+      else
+        LinkRes.AddFileName(maybequoted(s));
    end;
    end;
   if not LdSupportsNoResponseFile then
   if not LdSupportsNoResponseFile then
    LinkRes.Add(')');
    LinkRes.Add(')');
@@ -445,7 +449,10 @@ begin
      While not StaticLibFiles.Empty do
      While not StaticLibFiles.Empty do
       begin
       begin
         S:=StaticLibFiles.GetFirst;
         S:=StaticLibFiles.GetFirst;
-        LinkRes.AddFileName(maybequoted(s))
+        if LdSupportsNoResponseFile then
+          LinkRes.AddFileName(s)
+        else
+          LinkRes.AddFileName(maybequoted(s))
       end;
       end;
      if not LdSupportsNoResponseFile then
      if not LdSupportsNoResponseFile then
        LinkRes.Add(')');
        LinkRes.Add(')');
@@ -495,7 +502,10 @@ begin
   { frameworks for Darwin }
   { frameworks for Darwin }
   if IsDarwin then
   if IsDarwin then
     while not FrameworkFiles.empty do
     while not FrameworkFiles.empty do
-      LinkRes.Add('-framework '+FrameworkFiles.GetFirst);
+      begin
+        LinkRes.Add('-framework');
+        LinkRes.Add(FrameworkFiles.GetFirst);
+      end;
      
      
   { objects which must be at the end }
   { objects which must be at the end }
   if linklibc and
   if linklibc and
@@ -516,7 +526,10 @@ begin
   { ignore the fact that our relocations are in non-writable sections, }
   { ignore the fact that our relocations are in non-writable sections, }
   { will be fixed once we have pic support                             }
   { will be fixed once we have pic support                             }
   if isdll and IsDarwin Then
   if isdll and IsDarwin Then
-    LinkRes.Add('-read_only_relocs suppress');
+    begin
+      LinkRes.Add('-read_only_relocs');
+      LinkRes.Add('suppress');
+    end;
 { Write and Close response }
 { Write and Close response }
   linkres.writetodisk;
   linkres.writetodisk;
   linkres.Free;
   linkres.Free;