mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
Add support for position independent executables. This adds compile flags
-fpie & -fPIE which are similar to -fpic & -fPIC except that the resulting objects can not be used in shared libraries due to an additional optimization for pie. This also adds the -pie link flag which produces a pie executable given pic or pie objects. Combining -pie with -static is currently disabled. The only gcc3 arch that doesn't support pie at moment is arm due to binutils relocation bugs. ok kettenis@
This commit is contained in:
parent
69ee9c011c
commit
3497dfe12e
@ -93,7 +93,7 @@ Boston, MA 02111-1307, USA. */
|
|||||||
|
|
||||||
#undef SUBTARGET_EXTRA_ASM_SPEC
|
#undef SUBTARGET_EXTRA_ASM_SPEC
|
||||||
#define SUBTARGET_EXTRA_ASM_SPEC \
|
#define SUBTARGET_EXTRA_ASM_SPEC \
|
||||||
"-matpcs %{fpic:-k} %{fPIC:-k}"
|
"-matpcs %{fpic|fPIC|fpie|fPIE:-k}"
|
||||||
|
|
||||||
/* Default floating point model is soft-VFP.
|
/* Default floating point model is soft-VFP.
|
||||||
FIXME: -mhard-float currently implies FPA. */
|
FIXME: -mhard-float currently implies FPA. */
|
||||||
|
@ -21,7 +21,7 @@ Boston, MA 02111-1307, USA. */
|
|||||||
/* Definitions needed for OpenBSD, to avoid picking mips 'defaults'. */
|
/* Definitions needed for OpenBSD, to avoid picking mips 'defaults'. */
|
||||||
|
|
||||||
/* GAS must know this. */
|
/* GAS must know this. */
|
||||||
#define SUBTARGET_ASM_SPEC "%{fPIC:-KPIC} %|"
|
#define SUBTARGET_ASM_SPEC "%{fPIC|fPIE:-KPIC} %|"
|
||||||
|
|
||||||
/* CPP specific OpenBSD specs. */
|
/* CPP specific OpenBSD specs. */
|
||||||
#define SUBTARGET_CPP_SPEC OBSD_CPP_SPEC
|
#define SUBTARGET_CPP_SPEC OBSD_CPP_SPEC
|
||||||
|
@ -52,7 +52,7 @@ Boston, MA 02111-1307, USA. */
|
|||||||
|
|
||||||
#undef ASM_SPEC
|
#undef ASM_SPEC
|
||||||
#define ASM_SPEC "\
|
#define ASM_SPEC "\
|
||||||
%{v:-V} -s %{fpic:-K PIC} %{fPIC:-K PIC} \
|
%{v:-V} -s %{fpic|fPIC|fpie|fPIE:-K PIC} \
|
||||||
%{mlittle-endian:-EL} \
|
%{mlittle-endian:-EL} \
|
||||||
%(asm_cpu) %(asm_arch) \
|
%(asm_cpu) %(asm_arch) \
|
||||||
"
|
"
|
||||||
|
@ -304,7 +304,7 @@ in the following sections.
|
|||||||
@item Linker Options
|
@item Linker Options
|
||||||
@xref{Link Options,,Options for Linking}.
|
@xref{Link Options,,Options for Linking}.
|
||||||
@gccoptlist{@var{object-file-name} -l@var{library} @gol
|
@gccoptlist{@var{object-file-name} -l@var{library} @gol
|
||||||
-nostartfiles -nodefaultlibs -nostdlib @gol
|
-nostartfiles -nodefaultlibs -nostdlib -pie @gol
|
||||||
-s -static -static-libgcc -shared -shared-libgcc -symbolic @gol
|
-s -static -static-libgcc -shared -shared-libgcc -symbolic @gol
|
||||||
-Wl,@var{option} -Xlinker @var{option} @gol
|
-Wl,@var{option} -Xlinker @var{option} @gol
|
||||||
-u @var{symbol}}
|
-u @var{symbol}}
|
||||||
@ -657,7 +657,7 @@ in the following sections.
|
|||||||
-fasynchronous-unwind-tables @gol
|
-fasynchronous-unwind-tables @gol
|
||||||
-finhibit-size-directive -finstrument-functions @gol
|
-finhibit-size-directive -finstrument-functions @gol
|
||||||
-fno-common -fno-ident -fno-gnu-linker @gol
|
-fno-common -fno-ident -fno-gnu-linker @gol
|
||||||
-fpcc-struct-return -fpic -fPIC @gol
|
-fpcc-struct-return -fpic -fPIC -fpie -fPIE @gol
|
||||||
-freg-struct-return -fshared-data -fshort-enums @gol
|
-freg-struct-return -fshared-data -fshort-enums @gol
|
||||||
-fshort-double -fshort-wchar -fvolatile @gol
|
-fshort-double -fshort-wchar -fvolatile @gol
|
||||||
-fvolatile-global -fvolatile-static @gol
|
-fvolatile-global -fvolatile-static @gol
|
||||||
@ -4620,6 +4620,13 @@ library subroutines. (For example, @samp{__main}, used to ensure C++
|
|||||||
constructors will be called; @pxref{Collect2,,@code{collect2}, gccint,
|
constructors will be called; @pxref{Collect2,,@code{collect2}, gccint,
|
||||||
GNU Compiler Collection (GCC) Internals}.)
|
GNU Compiler Collection (GCC) Internals}.)
|
||||||
|
|
||||||
|
@item -pie
|
||||||
|
@opindex pie
|
||||||
|
Produce a position independent executable on targets which support it.
|
||||||
|
For predictable results, you must also specify the same set of options
|
||||||
|
that were used to generate code (@option{-fpie}, @option{-fPIE},
|
||||||
|
or model suboptions) when you specify this option.
|
||||||
|
|
||||||
@item -s
|
@item -s
|
||||||
@opindex s
|
@opindex s
|
||||||
Remove all symbol table and relocation information from the executable.
|
Remove all symbol table and relocation information from the executable.
|
||||||
@ -10776,6 +10783,15 @@ and the SPARC.
|
|||||||
Position-independent code requires special support, and therefore works
|
Position-independent code requires special support, and therefore works
|
||||||
only on certain machines.
|
only on certain machines.
|
||||||
|
|
||||||
|
@item -fpie
|
||||||
|
@itemx -fPIE
|
||||||
|
@opindex fpie
|
||||||
|
@opindex fPIE
|
||||||
|
These options are similar to @option{-fpic} and @option{-fPIC}, but
|
||||||
|
generated position independent code can be only linked into executables.
|
||||||
|
Usually these options are used when @option{-pie} GCC option will be
|
||||||
|
used during linking.
|
||||||
|
|
||||||
@item -ffixed-@var{reg}
|
@item -ffixed-@var{reg}
|
||||||
@opindex ffixed
|
@opindex ffixed
|
||||||
Treat the register named @var{reg} as a fixed register; generated code
|
Treat the register named @var{reg} as a fixed register; generated code
|
||||||
|
@ -483,6 +483,16 @@ extern int flag_pedantic_errors;
|
|||||||
|
|
||||||
extern int flag_pic;
|
extern int flag_pic;
|
||||||
|
|
||||||
|
/* Nonzero if we are compiling position independent code for executable.
|
||||||
|
1 vs 2 for a target-dependent "small" or "large" mode. */
|
||||||
|
|
||||||
|
extern int flag_pie;
|
||||||
|
|
||||||
|
/* Nonzero if we are compiling code for a shared library, zero for
|
||||||
|
executable. */
|
||||||
|
|
||||||
|
extern int flag_shlib;
|
||||||
|
|
||||||
/* Nonzero means generate extra code for exception handling and enable
|
/* Nonzero means generate extra code for exception handling and enable
|
||||||
exception handling. */
|
exception handling. */
|
||||||
|
|
||||||
|
@ -639,6 +639,8 @@ proper position among the other output files. */
|
|||||||
#define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G"
|
#define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define LINK_PIE_SPEC "%{pie: -pie}"
|
||||||
|
|
||||||
/* -u* was put back because both BSD and SysV seem to support it. */
|
/* -u* was put back because both BSD and SysV seem to support it. */
|
||||||
/* %{static:} simply prevents an error message if the target machine
|
/* %{static:} simply prevents an error message if the target machine
|
||||||
doesn't handle -static. */
|
doesn't handle -static. */
|
||||||
@ -647,8 +649,12 @@ proper position among the other output files. */
|
|||||||
directories. */
|
directories. */
|
||||||
#ifndef LINK_COMMAND_SPEC
|
#ifndef LINK_COMMAND_SPEC
|
||||||
#define LINK_COMMAND_SPEC "\
|
#define LINK_COMMAND_SPEC "\
|
||||||
|
%{pie:%{static:%e-pie and -static options are incompatible}} \
|
||||||
|
%{shared:%{pie:%e-shared and -pie options are incompatible}} \
|
||||||
|
%{pie:%{pg|p:%e-pie and -pg|p options are incompatible}} \
|
||||||
%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
|
%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
|
||||||
%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t}\
|
%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t}\
|
||||||
|
" LINK_PIE_SPEC "\
|
||||||
%{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
|
%{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
|
||||||
%{static:} %{L*} %(link_libgcc) %o %{!nostdlib:%{!nodefaultlibs:%(link_gcc_c_sequence)}}\
|
%{static:} %{L*} %(link_libgcc) %o %{!nostdlib:%{!nodefaultlibs:%(link_gcc_c_sequence)}}\
|
||||||
%{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"
|
%{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"
|
||||||
@ -973,6 +979,7 @@ static const struct option_map option_map[] =
|
|||||||
{"--output-class-directory", "-foutput-class-dir=", "ja"},
|
{"--output-class-directory", "-foutput-class-dir=", "ja"},
|
||||||
{"--param", "--param", "a"},
|
{"--param", "--param", "a"},
|
||||||
{"--pedantic", "-pedantic", 0},
|
{"--pedantic", "-pedantic", 0},
|
||||||
|
{"--pie", "-pie", 0},
|
||||||
{"--pedantic-errors", "-pedantic-errors", 0},
|
{"--pedantic-errors", "-pedantic-errors", 0},
|
||||||
{"--pipe", "-pipe", 0},
|
{"--pipe", "-pipe", 0},
|
||||||
{"--prefix", "-B", "a"},
|
{"--prefix", "-B", "a"},
|
||||||
|
@ -710,6 +710,17 @@ int flag_delayed_branch;
|
|||||||
|
|
||||||
int flag_pic;
|
int flag_pic;
|
||||||
|
|
||||||
|
/* Nonzero if we are compiling position independent code for executable.
|
||||||
|
The value is 1 if we are doing "small" pic; value is 2 if we're doing
|
||||||
|
"large" pic. */
|
||||||
|
int flag_pie;
|
||||||
|
|
||||||
|
/* Nonzero if we are compiling code for a shared library, zero for
|
||||||
|
executable. */
|
||||||
|
|
||||||
|
int flag_shlib;
|
||||||
|
|
||||||
|
|
||||||
/* Set to the default thread-local storage (tls) model to use. */
|
/* Set to the default thread-local storage (tls) model to use. */
|
||||||
|
|
||||||
enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
|
enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
|
||||||
@ -1102,6 +1113,9 @@ static const lang_independent_options f_options[] =
|
|||||||
{"pic", &flag_pic, 1,
|
{"pic", &flag_pic, 1,
|
||||||
N_("Generate position independent code, if possible") },
|
N_("Generate position independent code, if possible") },
|
||||||
{"PIC", &flag_pic, 2, ""},
|
{"PIC", &flag_pic, 2, ""},
|
||||||
|
{"pie", &flag_pie, 1,
|
||||||
|
N_("Generate position independent code for executables, if possible") },
|
||||||
|
{"PIE", &flag_pie, 2, ""},
|
||||||
{"exceptions", &flag_exceptions, 1,
|
{"exceptions", &flag_exceptions, 1,
|
||||||
N_("Enable exception handling") },
|
N_("Enable exception handling") },
|
||||||
{"unwind-tables", &flag_unwind_tables, 1,
|
{"unwind-tables", &flag_unwind_tables, 1,
|
||||||
@ -5083,6 +5097,12 @@ parse_options_and_default_flags (argc, argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flag_pie)
|
||||||
|
flag_pic = flag_pie;
|
||||||
|
|
||||||
|
if (flag_pic && !flag_pie)
|
||||||
|
flag_shlib = 1;
|
||||||
|
|
||||||
if (flag_no_inline == 2)
|
if (flag_no_inline == 2)
|
||||||
flag_no_inline = 0;
|
flag_no_inline = 0;
|
||||||
else
|
else
|
||||||
|
@ -5460,7 +5460,7 @@ bool
|
|||||||
default_binds_local_p (exp)
|
default_binds_local_p (exp)
|
||||||
tree exp;
|
tree exp;
|
||||||
{
|
{
|
||||||
return default_binds_local_p_1 (exp, flag_pic);
|
return default_binds_local_p_1 (exp, flag_shlib);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
Loading…
Reference in New Issue
Block a user