Andi Kleen
2007-Apr-18 17:49 UTC
[PATCH 1 of 1] x86_64: Put .note.* sections into a PT_NOTE segment in vmlinux II
On Tuesday 22 August 2006 16:26, Ian Campbell wrote:> This patch updates x86_64 linker script to pack any .note.* sections > into a PT_NOTE segment in the output file.Sorry I tried to apply it, but at least 2.6.18rc4 mainline (which my tree is based on) doesn't have a NOTES macro so it doesn't link I dropped the NOTES addition for now, presumably it will need to be readded later. -Andi
Jeremy Fitzhardinge
2007-Apr-18 17:49 UTC
[PATCH 1 of 1] x86_64: Put .note.* sections into a PT_NOTE segment in vmlinux
Ian Campbell wrote:> It has been suggested to me that the notes segment should have flags 0 > (i.e. not readable) since it is only used by the loader and is not used > at runtime. For now I went with a readable segment since that is what > the i386 patch uses. >Note that the PT_NOTEs segment is aliased to a part of one of the PT_LOADs - ie, it points into the data segment. So making it -rwx would either be ignored, or also require putting the bits into a new PT_LOAD segment with 0 permissions, which is pretty pointless. I made it R_E just so there was no permissions conflict, though the _E part could probably go. J
Ian Campbell
2007-Apr-18 17:49 UTC
[PATCH 1 of 1] x86_64: Put .note.* sections into a PT_NOTE segment in vmlinux
This patch updates x86_64 linker script to pack any .note.* sections into a PT_NOTE segment in the output file. To do this, we tell ld that we need a PT_NOTE segment. This requires us to start explicitly mapping sections to segments, so we also need to explicitly create PT_LOAD segments for text and data, and map the sections to them appropriately. Fortunately, each section will default to its previous section's segment, so it doesn't take many changes to vmlinux.lds.S. The corresponding change is already made for i386 in -mm and I'd like this patch to join it. The section to segment mappings do change as do the segment flags so some time in -mm would be good for that reason as well, just in case. In particular .data and .bss move from the text segment to the data segment and .data.cacheline_aligned .data.read_mostly are put in the data segment instead of a separate one. I think that it would be possible to exactly match the existing section to segment mapping and flags but it would be a more intrusive change and I'm not sure there is a reason for the existing layout other than it is what you get by default if you don't explicitly specify something else. If there is a reason for the existing layout then I will of course make the more intrusive change. If there is no reason we could probably drop the executable or writable flags from some segments but I don't know how much attention is paid to them anyway so it might not be worth the effort. The vsyscall related sections need to go in a different segment to the normal data segment and so I invented a "user" segment to contain them. I believe this should appear to be another data segment as far as the kernel is concerned so the flags are setup accordingly. The notes will be used in the Xen paravirt_ops backend to provide additional information to the domain builder. I am in the process of converting the xen-unstable kernels and tools over to this scheme at the moment to support this in the future. It has been suggested to me that the notes segment should have flags 0 (i.e. not readable) since it is only used by the loader and is not used at runtime. For now I went with a readable segment since that is what the i386 patch uses. Signed-off-by: Ian Campbell <ian.campbell@xensource.com> diff --git a/arch/x86_64/kernel/vmlinux.lds.S b/arch/x86_64/kernel/vmlinux.lds.S index 7c4de31..ef418b3 100644 --- a/arch/x86_64/kernel/vmlinux.lds.S +++ b/arch/x86_64/kernel/vmlinux.lds.S @@ -13,6 +13,12 @@ OUTPUT_FORMAT("elf64-x86-64", "elf64-x86 OUTPUT_ARCH(i386:x86-64) ENTRY(phys_startup_64) jiffies_64 = jiffies; +PHDRS { + text PT_LOAD FLAGS(5); /* R_E */ + data PT_LOAD FLAGS(7); /* RWE */ + user PT_LOAD FLAGS(7); /* RWE */ + note PT_NOTE FLAGS(4); /* R__ */ +} SECTIONS { . = __START_KERNEL; @@ -31,7 +37,7 @@ SECTIONS KPROBES_TEXT *(.fixup) *(.gnu.warning) - } = 0x9090 + } :text = 0x9090 /* out-of-line lock text */ .text.lock : AT(ADDR(.text.lock) - LOAD_OFFSET) { *(.text.lock) } @@ -57,7 +63,7 @@ #endif .data : AT(ADDR(.data) - LOAD_OFFSET) { *(.data) CONSTRUCTORS - } + } :data _edata = .; /* End of data section */ @@ -89,7 +95,7 @@ #define VVIRT_OFFSET (VSYSCALL_ADDR - VS #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET) . = VSYSCALL_ADDR; - .vsyscall_0 : AT(VSYSCALL_PHYS_ADDR) { *(.vsyscall_0) } + .vsyscall_0 : AT(VSYSCALL_PHYS_ADDR) { *(.vsyscall_0) } :user __vsyscall_0 = VSYSCALL_VIRT_ADDR; . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); @@ -132,7 +138,7 @@ #undef VVIRT . = ALIGN(8192); /* init_task */ .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) { *(.data.init_task) - } + } :data . = ALIGN(4096); .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) { @@ -235,4 +241,6 @@ #endif STABS_DEBUG DWARF_DEBUG + + NOTES }
Andi Kleen
2007-Apr-18 17:49 UTC
[PATCH 1 of 1] x86_64: Put .note.* sections into a PT_NOTE segment in vmlinux
On Tuesday 22 August 2006 16:26, Ian Campbell wrote:> This patch updates x86_64 linker script to pack any .note.* sections > into a PT_NOTE segment in the output file.Thanks added. -Andi P.S.: 2-3 paragraphs description would have been enough, but that is fine too.
Possibly Parallel Threads
- [PATCH] kexec-tools: Read always one vmcoreinfo file
- update for x86_64-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch
- [patch 0/8] Basic infrastructure patches for a paravirtualized kernel
- [patch 0/8] Basic infrastructure patches for a paravirtualized kernel
- [PATCH 3/4] extract vmcoreinfo from /proc/vmcore for Xen