$OpenBSD: patch-fpcsrc_compiler_systems_t_bsd_pas,v 1.4 2017/02/04 15:23:04 pascal Exp $

Correct library search path for OpenBSD; always add -nopie to linker flags.

Do not link to /usr/libexec/ld.so as a shared library.

--- fpcsrc/compiler/systems/t_bsd.pas.orig	Sun Dec  7 21:27:02 2014
+++ fpcsrc/compiler/systems/t_bsd.pas	Sat Feb  4 09:51:46 2017
@@ -126,7 +126,10 @@ begin
   Inherited Create;
   if not Dontlinkstdlibpath Then
    if not(target_info.system in systems_darwin) then
-     LibrarySearchPath.AddPath(sysrootpath,'/lib;/usr/lib;/usr/X11R6/lib',true)
+     if not(target_info.system in systems_openbsd) then
+       LibrarySearchPath.AddPath(sysrootpath,'/lib;/usr/lib;/usr/X11R6/lib',true)
+     else
+       LibrarySearchPath.AddPath(sysrootpath,'/usr/lib;${X11BASE}/lib;${LOCALBASE}/lib',true)
    else
      { Mac OS X doesn't have a /lib }
      LibrarySearchPath.AddPath(sysrootpath,'/usr/lib',true)
@@ -581,7 +584,8 @@ begin
      { when we have -static for the linker the we also need libgcc }
      if (cs_link_staticflag in current_settings.globalswitches) then
       LinkRes.Add('-lgcc');
-     if linkdynamic and (Info.DynamicLinker<>'') then
+     if linkdynamic and (Info.DynamicLinker<>'') and
+        not(target_info.system in systems_openbsd) then
       LinkRes.AddFileName(Info.DynamicLinker);
      if not LdSupportsNoResponseFile then
        LinkRes.Add(')');
@@ -697,8 +701,7 @@ begin
    end;
    
 { Use -nopie on OpenBSD }
-  if (target_info.system in systems_openbsd) and
-     (target_info.system <> system_x86_64_openbsd) then
+  if (target_info.system in systems_openbsd) then
     Info.ExtraOptions:=Info.ExtraOptions+' -nopie';
     
 { Write used files and libraries }
