diff --git a/compiler/globtype.pas b/compiler/globtype.pas index 1106e2459e..a38fd28c08 100644 --- a/compiler/globtype.pas +++ b/compiler/globtype.pas @@ -194,7 +194,8 @@ interface cs_link_strip,cs_link_staticflag,cs_link_on_target,cs_link_extern,cs_link_opt_vtable, cs_link_opt_used_sections,cs_link_separate_dbg_file, cs_link_map,cs_link_pthread,cs_link_no_default_lib_order, - cs_link_native + cs_link_native, + cs_link_pre_binutils_2_19 ); tglobalswitches = set of tglobalswitch; diff --git a/compiler/msg/errore.msg b/compiler/msg/errore.msg index ec7e7d2231..79bb6001b7 100644 --- a/compiler/msg/errore.msg +++ b/compiler/msg/errore.msg @@ -3880,6 +3880,7 @@ A*2WR_Generate relocation code (Windows) P*2WT_Specify MPW tool type application (Classic Mac OS) **2WX_Enable executable stack (Linux) **1X_Executable options: +**2X9_Generate linkerscript for GNU Binutils ld older than version 2.19.1 (Linux) **2Xc_Pass --shared/-dynamic to the linker (BeOS, Darwin, FreeBSD, Linux) **2Xd_Do not search default library path (sometimes required for cross-compiling when not using -XR) **2Xe_Use external linker diff --git a/compiler/msgidx.inc b/compiler/msgidx.inc index 2dc01139f5..257e20a42d 100644 --- a/compiler/msgidx.inc +++ b/compiler/msgidx.inc @@ -1017,7 +1017,7 @@ const option_info=11024; option_help_pages=11025; - MsgTxtSize = 76005; + MsgTxtSize = 76087; MsgIdxMax : array[1..20] of longint=( 26,99,342,124,96,58,127,32,207,64, diff --git a/compiler/msgtxt.inc b/compiler/msgtxt.inc index c678fae380..02106e1046 100644 --- a/compiler/msgtxt.inc +++ b/compiler/msgtxt.inc @@ -1,7 +1,7 @@ {$ifdef Delphi} -const msgtxt : array[0..000316] of string[240]=( +const msgtxt : array[0..000317] of string[240]=( {$else Delphi} -const msgtxt : array[0..000316,1..240] of char=( +const msgtxt : array[0..000317,1..240] of char=( {$endif Delphi} '01000_T_Compiler: $1'#000+ '01001_D_Compiler OS: $1'#000+ @@ -1722,36 +1722,39 @@ const msgtxt : array[0..000316,1..240] of char=( 'P*2WT_Specify MPW tool type application (Classic Mac OS)'#010+ '**2WX_Enable executable stack (Linux)'#010+ '**1X_Executable options:'#010+ - '**2Xc_Pass --shared/-dynamic to the linker (BeOS, Darwin, FreeBSD',', L'+ - 'inux)'#010+ + '**2X9_Generate linkerscript for GNU Binutils ld older than versio','n 2'+ + '.19.1 (Linux)'#010+ + '**2Xc_Pass --shared/-dynamic to the linker (BeOS, Darwin, FreeBSD, Lin'+ + 'ux)'#010+ '**2Xd_Do not search default library path (sometimes required for cross'+ '-compiling when not using -XR)'#010+ '**2Xe_Use external linker'#010+ - '**2Xf_Substitute pthread library name for linking (BSD)'#010+ - '**2Xg_Create debuginfo in a separate file and ad','d a debuglink sectio'+ - 'n to executable'#010+ + '**2Xf_Substitute pthre','ad library name for linking (BSD)'#010+ + '**2Xg_Create debuginfo in a separate file and add a debuglink section '+ + 'to executable'#010+ '**2XD_Try to link units dynamically (defines FPC_LINK_DYNAMIC)'#010+ '**2Xi_Use internal linker'#010+ - '**2XLA_Define library substitutions for linking'#010+ + '**2XLA_Define library substi','tutions for linking'#010+ '**2XLO_Define order of library linking'#010+ - '**2XLD_Exclude default ','order of standard libraries'#010+ + '**2XLD_Exclude default order of standard libraries'#010+ '**2Xm_Generate link map'#010+ '**2XM_Set the name of the '#039'main'#039' program routine (default i'+ 's '#039'main'#039')'#010+ - '**2Xn_Use target system native linker instead of GNU ld (Solaris, AIX)'+ - #010+ - 'F*2Xp_First search for the compiler binary',' in the directory '#010+ + '**2Xn_Use target system native lin','ker instead of GNU ld (Solaris, AI'+ + 'X)'#010+ + 'F*2Xp_First search for the compiler binary in the directory '#010+ '**2XP_Prepend the binutils names with the prefix '#010+ '**2Xr_Set the linker'#039's rlink-path to (needed for cross comp'+ - 'ile, see the ld manual for more information) (BeOS, Linux)'#010+ - '**2XR_Prepend to all linker se','arch paths (BeOS, Darwin, FreeB'+ - 'SD, Linux, Mac OS, Solaris)'#010+ + 'ile, see the l','d manual for more information) (BeOS, Linux)'#010+ + '**2XR_Prepend to all linker search paths (BeOS, Darwin, FreeBSD'+ + ', Linux, Mac OS, Solaris)'#010+ '**2Xs_Strip all symbols from executable'#010+ - '**2XS_Try to link units statically (default, defines FPC_LINK_STATIC)'#010+ + '**2XS_Try to link units statically (default, defines FPC_LI','NK_STATIC'+ + ')'#010+ '**2Xt_Link with static libraries (-static is passed to linker)'#010+ - '**2Xv_Ge','nerate table for Virtual Entry calls'#010+ + '**2Xv_Generate table for Virtual Entry calls'#010+ '**2XX_Try to smartlink units (defines FPC_LINK_SMART)'#010+ '**1*_'#010+ '**1?_Show this help'#010+ - '**1h_Shows this help without waiting' + '**1h_Shows this help without ','waiting' ); diff --git a/compiler/options.pas b/compiler/options.pas index d7075539a2..f187149957 100644 --- a/compiler/options.pas +++ b/compiler/options.pas @@ -2347,6 +2347,18 @@ begin while j<=length(more) do begin case More[j] of + '9' : + begin + if target_info.system in systems_linux then + begin + if UnsetBool(More, j, opt, false) then + exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19) + else + include(init_settings.globalswitches,cs_link_pre_binutils_2_19); + end + else + IllegalPara(opt); + end; 'c' : Cshared:=TRUE; 'd' : Dontlinkstdlibpath:=TRUE; 'e' : diff --git a/compiler/systems/t_linux.pas b/compiler/systems/t_linux.pas index 299f1f8a39..03c3cc1233 100644 --- a/compiler/systems/t_linux.pas +++ b/compiler/systems/t_linux.pas @@ -318,8 +318,12 @@ begin begin ExeCmd[1]:='ld '+platform_select+platformopt+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE'; DllCmd[1]:='ld '+platform_select+' $OPT $INIT $FINI $SONAME -shared -L. -o $EXE'; - { when we want to cross-link we need to override default library paths } - if length(sysrootpath) > 0 then + { when we want to cross-link we need to override default library paths; + when targeting binutils 2.19 or later, we use the "INSERT" command to + augment the default linkerscript, which also requires -T (normally that + option means "completely replace the default linkerscript) } + if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) or + (length(sysrootpath)>0) then begin ExeCmd[1]:=ExeCmd[1]+' -T'; DllCmd[1]:=DllCmd[1]+' -T'; @@ -590,29 +594,39 @@ begin end; end; - {Entry point. Only needed for executables, set on the linker command line for - shared libraries. } + { Entry point. Only needed for executables, as for shared lubraries we use + the -init command line option instead + + The "ENTRY" linkerscript command does not have any effect when augmenting + a linker script, so use the command line parameter instead } if (not isdll) then - if (linksToSharedLibFiles and not linklibc) then - add('ENTRY(_dynamic_start)') - else - add('ENTRY(_start)'); + if (linksToSharedLibFiles and not linklibc) then + info.ExeCmd[1]:=info.ExeCmd[1]+' -e _dynamic_start' + else + info.ExeCmd[1]:=info.ExeCmd[1]+' -e _start'; { If we are using the default sysroot, use the default linker script and - just augment it with the FPC-specific parts. Ideally, we should add - "INSERT AFTER" at the end to explicitly tell ld to just augment the - built-in linker script, but that's only supported by ld 2.19 and later. + just augment it with the FPC-specific parts. } if sysrootpath='' then begin add('SECTIONS'); add('{'); - add(' .data :'); + if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) then + { we can't use ".data", as that would hide the .data from the + original linker script in combination with the INSERT at the end } + add(' .fpcdata :') + else + add(' .data :'); add(' {'); add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))'); add(' }'); - add(' .threadvar _edata : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }'); + add(' .threadvar : { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }'); add('}'); + { this "INSERT" means "merge into the original linker script, even if + -T is used" } + if not(cs_link_pre_binutils_2_19 in current_settings.globalswitches) then + add('INSERT AFTER .data;'); end else begin