4 # Copyright 2013 Texas Instruments, Inc.
5 # Russ Dill <russ.dill@ti.com>
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms and conditions of the GNU General Public License,
9 # version 2, as published by the Free Software Foundation.
14 # Report unresolved symbol references
15 ldflags-y += --no-undefined
16 # Delete all temporary local symbols
19 # Reset objcopy flags, ARM puts "-O binary" here
22 # Reference gcc builtins for use in PIE with __pie_
23 $(obj)/pie_rename.syms: $(KBUILD_LIBPIE)
24 @$(NM) $^ | awk '{if ($$3) print $$3,"__pie_"$$3}' > $@
26 # For weakening the links to the original gcc builtins
27 $(obj)/pie_weaken.syms: $(KBUILD_LIBPIE)
28 @$(NM) $^ | awk '{if ($$3) print "__pie_"$$3}' > $@
30 # For embedding address of the symbols copied from the PIE into the kernel
31 $(obj)/pie.syms: $(obj)/pie.elf
32 @$(NM) $^ | awk '{if ($$3 && $$2 == toupper($$2)) print $$3,"=","0x"$$1" + _binary_pie_pie_bin_start;"}' > $@
34 # Collect together the libpie objects
35 LDFLAGS_libpie_stage1.o += -r
37 $(obj)/libpie_stage1.o: $(KBUILD_LIBPIE)
40 # Rename the libpie gcc builtins with a __pie_ prefix
41 OBJCOPYFLAGS_libpie_stage2.o += --redefine-syms=$(obj)/pie_rename.syms
42 OBJCOPYFLAGS_libpie_stage2.o += --rename-section .text=.pie.text
44 $(obj)/libpie_stage2.o: $(obj)/libpie_stage1.o $(obj)/pie_rename.syms
45 $(call if_changed,objcopy)
47 # Generate a version of vmlinux.o with weakened and rename references to gcc
49 OBJCOPYFLAGS_pie_stage1.o += --weaken-symbols=$(obj)/pie_weaken.syms
50 OBJCOPYFLAGS_pie_stage1.o += --redefine-syms=$(obj)/pie_rename.syms
52 $(obj)/pie_stage1.o: $(obj)/../vmlinux.o $(obj)/pie_rename.syms $(obj)/pie_weaken.syms
53 $(call if_changed,objcopy)
55 # Drop in the PIE versions instead
56 LDFLAGS_pie_stage2.o += -r
57 # Allow the _GLOBAL_OFFSET_TABLE to redefine
58 LDFLAGS_pie_stage2.o += --defsym=_GLOBAL_OFFSET_TABLE_=_GLOBAL_OFFSET_TABLE_
60 $(obj)/pie_stage2.o: $(obj)/pie_stage1.o $(obj)/libpie_stage2.o
63 # Drop everything but the pie sections
64 OBJCOPYFLAGS_pie_stage3.o += -j ".pie.*"
65 OBJCOPYFLAGS_pie_stage3.o += -j ".pie.text"
66 OBJCOPYFLAGS_pie_stage3.o += -j ".pie.rk3036.text" -j ".pie.rk3036.data"
67 OBJCOPYFLAGS_pie_stage3.o += -j ".pie.rk312x.text" -j ".pie.rk312x.data"
68 OBJCOPYFLAGS_pie_stage3.o += -j ".pie.rk3188.text" -j ".pie.rk3188.data"
69 OBJCOPYFLAGS_pie_stage3.o += -j ".pie.rk3288.text" -j ".pie.rk3288.data"
71 $(obj)/pie_stage3.o: $(obj)/pie_stage2.o
72 $(call if_changed,objcopy)
74 # Create the position independant executable
75 LDFLAGS_pie.elf += -T $(KBUILD_PIE_LDS) --pie --gc-sections
77 $(obj)/pie.elf: $(obj)/pie_stage3.o $(KBUILD_PIE_LDS)
80 # Create binary data for the kernel
81 OBJCOPYFLAGS_pie.bin += -O binary
83 $(obj)/pie.bin: $(obj)/pie.elf $(obj)/pie.syms
84 $(call if_changed,objcopy)
86 # Import the data into the kernel
87 OBJCOPYFLAGS_pie.bin.o += -B $(ARCH) -I binary -O $(OBJCOPY_OUTPUT_FORMAT)
89 $(obj)/pie.bin.o: $(obj)/pie.bin
90 $(call if_changed,objcopy)
92 extra-y += pie_rename.syms pie_weaken.syms pie.syms pie.elf pie.bin