Commit 41999f40 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

x86: Start using native object relocatable files in parasite code

Since at the moment we're running only x86-64 not 32 bit tasks,
and our code is not carrying any big statically defined structures
we can use relocatable files directly with all relocation applied
during building.

This gonna be changed soon once we start supporting 32 bit tasks.

IOW even currently we need (which is not yet done but it's safe)

 - check for gotpcrel relocations
 - apply relocations with generated elf_apply_relocs helper

Currently overall scheme looks this way

 - our object files are linked together into parasite.built-in.bin.o file
 - then pie/piegen/piegen tool is called which parses this file and generates
   C source code file with bytestream and all information needed to rellocate
   this bytestream into a new place (see elf_apply_relocs helper)
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent b6668af6
...@@ -188,13 +188,13 @@ $(ARCH_DIR): protobuf config ...@@ -188,13 +188,13 @@ $(ARCH_DIR): protobuf config
$(Q) $(MAKE) $(build)=$(ARCH_DIR) all $(Q) $(MAKE) $(build)=$(ARCH_DIR) all
ifneq ($(filter i386 ia32 x86_64, $(ARCH)),) ifneq ($(filter i386 ia32 x86_64, $(ARCH)),)
pie/piegen/%: pie/piegen/%: config
$(Q) $(MAKE) $(build)=pie/piegen $@ $(Q) $(MAKE) $(build)=pie/piegen $@
pie/piegen: pie/piegen: config
$(Q) $(MAKE) $(build)=pie/piegen all $(Q) $(MAKE) $(build)=pie/piegen all
$(PIEGEN): pie/piegen/built-in.o $(PIEGEN): pie/piegen/built-in.o
$(E) " LINK " $@ $(E) " LINK " $@
$(Q) $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@ $(Q) $(CC) $(CFLAGS) pie/piegen/built-in.o $(LDFLAGS) -o $@
.PHONY: pie/piegen .PHONY: pie/piegen
endif endif
......
...@@ -49,6 +49,34 @@ PIELDS := pie.lds.S ...@@ -49,6 +49,34 @@ PIELDS := pie.lds.S
.SECONDARY: .SECONDARY:
ifneq ($(filter i386 ia32 x86_64, $(ARCH)),)
ldflags-y += -r
target-name = $(patsubst pie/%-blob.h,%,$(1))
ifeq ($(ARCH),x86_64)
$(obj)/$(PIELDS): $(obj)/pie-reloc.lds.S.in
$(E) " GEN " $@
$(Q) echo "OUTPUT_ARCH(i386:x86-64)" > $(obj)/$(PIELDS)
$(Q) echo "TARGET(elf64-x86-64)" >> $(obj)/$(PIELDS)
$(Q) cat $< >> $(obj)/$(PIELDS)
else
$(obj)/$(PIELDS): $(obj)/pie-reloc.lds.S.in
$(E) " GEN " $@
$(Q) echo "OUTPUT_ARCH(i386)" > $(obj)/$(PIELDS)
$(Q) echo "TARGET(elf32-i386)" >> $(obj)/$(PIELDS)
$(Q) cat $< >> $(obj)/$(PIELDS)
endif
$(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/$(PIELDS)
$(E) " GEN " $@
$(Q) $(LD) $(ldflags-y) -T $(obj)/$(PIELDS) -o $@ $<
$(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(obj)/$(PIELDS) pie/piegen
$(E) " GEN " $@
$(Q) pie/piegen/piegen -f $< -p $(call target-name,$@)_blob_offset__ -s $(call target-name,$@)_blob > $@
else
$(obj)/$(PIELDS): $(obj)/$(PIELDS).in $(obj)/$(PIELDS): $(obj)/$(PIELDS).in
$(E) " GEN " $@ $(E) " GEN " $@
$(Q) $(SH) -c "echo 'OUTPUT_ARCH($(LDARCH))' > $(obj)/$(PIELDS)" $(Q) $(SH) -c "echo 'OUTPUT_ARCH($(LDARCH))' > $(obj)/$(PIELDS)"
...@@ -66,6 +94,8 @@ $(obj)/%-blob.h: $(obj)/%.built-in.bin $(obj)/$(GEN-OFFSETS) ...@@ -66,6 +94,8 @@ $(obj)/%-blob.h: $(obj)/%.built-in.bin $(obj)/$(GEN-OFFSETS)
$(E) " GEN " $@ $(E) " GEN " $@
$(Q) $(SH) $(obj)/$(GEN-OFFSETS) $(@:-blob.h=) $(notdir $(@:-blob.h=)) $(CROSS_COMPILE) > $@ $(Q) $(SH) $(obj)/$(GEN-OFFSETS) $(@:-blob.h=) $(notdir $(@:-blob.h=)) $(CROSS_COMPILE) > $@
endif
$(BLOBS): $(obj)/$(PIELDS) $(BLOBS): $(obj)/$(PIELDS)
_all += $(BLOBS) _all += $(BLOBS)
......
SECTIONS
{
.text : {
*(.head.text)
*(.text*)
}
.data : {
*(.data*)
*(.bss*)
}
.rodata : {
*(.rodata*)
*(.got*)
*(.toc*)
}
/DISCARD/ : {
*(.debug*)
*(.comment*)
*(.note*)
*(.group*)
*(.eh_frame*)
}
__export_parasite_args = .;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment