kexec-tools: powerpc: Fix 64bit optimize for size (gcc -Os) build
Subsystems (2)
PATCH 1/3 kexec-tools: powerpc: Fix 64bit optimize for size (gcc -Os) build
commit 46b2d0b8a719 (kexec/powerpc fix optimization for size (gcc -Os) build) added out of line GPR save/restore handlers for 32bit -Os builds. This patch adds the handlers for 64bit builds.
---
purgatory/arch/ppc64/Makefile +1 -0
@@ -7,6 +7,7 @@ ppc64_PURGATORY_SRCS += purgatory/arch/p ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/purgatory-ppc64.c ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/console-ppc64.c ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/crashdump_backup.c +ppc64_PURGATORY_SRCS += purgatory/arch/ppc64/misc.S ppc64_PURGATORY_EXTRA_CFLAGS += -m64 -mcall-aixdesc ppc64_PURGATORY_EXTRA_ASFLAGS += -m64 -mcall-aixdesc
purgatory/arch/ppc64/misc.S new file +197 -0
197 lines not on this page · raw message
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH 2/3 kexec-tools: powerpc: Add more 64bit relocations
Add all the TOC16 relocations. These were hit when building kexec with a recent toolchain.
---
kexec/arch/ppc64/kexec-elf-rel-ppc64.c +36 -8
@@ -46,6 +46,19 @@ unsigned long my_r2(const struct mem_ehdreturn shdr->sh_addr +0x8000 ; } +static void do_relative_toc (unsigned long value,uint16_t *location, +unsigned long mask,int complain_signed) +{ +if (complain_signed && (value +0x8000 >0xffff )) { +die ("TOC16 relocation overflows (%lu)\n" , value); + } + +if ((~mask &0xffff ) & value) { +die ("bad TOC16 relocation (%lu)\n" , value); + } + + *location = (*location & ~mask) | (value & mask); +}void machine_apply_elf_rel (struct mem_ehdr *ehdr,unsigned long r_type,void *location,unsigned long address,unsigned long value)
@@ -70,15 +83,30 @@ void machine_apply_elf_rel(struct mem_eh *(uint64_t *)location =my_r2 (ehdr);break ; +case R_PPC64_TOC16 : +do_relative_toc (value -my_r2 (ehdr), location,0xffff ,1 ); +break ; +case R_PPC64_TOC16_DS : -/* Subtact TOC pointer */ - value -=my_r2 (ehdr); -if ((value &3 ) !=0 || value +0x8000 >0xffff ) { -die ("bad TOC16_DS relocation (%lu)\n" , value); - } - *((uint16_t *) location) - = (*((uint16_t *) location) & ~0xfffc ) - | (value &0xfffc ); +do_relative_toc (value -my_r2 (ehdr), location,0xfffc ,1 ); +break ; + +case R_PPC64_TOC16_LO : +do_relative_toc (value -my_r2 (ehdr), location,0xffff ,0 ); +break ; + +case R_PPC64_TOC16_LO_DS : +do_relative_toc (value -my_r2 (ehdr), location,0xfffc ,0 ); +break ; + +case R_PPC64_TOC16_HI : +do_relative_toc ((value -my_r2 (ehdr)) >>16 , location, +0xffff ,0 ); +break ; + +case R_PPC64_TOC16_HA : +do_relative_toc ((value -my_r2 (ehdr) +0x8000 ) >>16 , location, +0xffff ,0 );break ;case R_PPC64_REL24 :
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 6 lines · Anton Blanchard
commit
46b2d0b8a719(kexec/powerpc fix optimization for size (gcc -Os) build) added out of line GPR save/restore handlers for 32bit -Os builds. This patch adds the handlers for 64bit builds.Signed-off-by Anton Blanchard <[email protected]>
Quoted 9 lines · Anton Blanchard
Some cleanup of the relocation code:
- Whitespace changes
- Use braces to add clarity to nested for/if loop.
- Order ADDR16 relocations
- No need for to return from a void function.Signed-off-by Anton Blanchard <[email protected]>
Quoted 5 lines · Anton Blanchard
Add all the TOC16 relocations. These were hit when building kexec with a recent toolchain.
Signed-off-by Anton Blanchard <[email protected]>
Thanks Anton,
I have applied all three patches.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH 3/3 kexec-tools: powerpc: Cleanup relocation code
In reply to Anton BlanchardSome cleanup of the relocation code:
- Whitespace changes
- Use braces to add clarity to nested for/if loop.
- Order ADDR16 relocations
- No need for to return from a void function.
---
kexec/arch/ppc64/kexec-elf-rel-ppc64.c +21 -16
@@ -16,6 +16,7 @@ int machine_verify_elf_rel(struct mem_ehif (ehdr->e_machine !=EM_PPC64 ) {return 0 ; } +return 1 ; }
@@ -23,13 +24,16 @@ static struct mem_shdr *toc_section(cons {struct mem_shdr *shdr, *shdr_end;unsigned char *strtab; + strtab = (unsigned char *)ehdr->e_shdr[ehdr->e_shstrndx].sh_data; shdr_end = &ehdr->e_shdr[ehdr->e_shnum]; -for (shdr = ehdr->e_shdr; shdr != shdr_end; shdr++) -if ( shdr->sh_size && -strcmp ((char *)&strtab[shdr->sh_name], -".toc" ) ==0 ) +for (shdr = ehdr->e_shdr; shdr != shdr_end; shdr++) { +if (shdr->sh_size && +strcmp ((char *)&strtab[shdr->sh_name],".toc" ) ==0 ) {return shdr; + } + } +return NULL ; }
@@ -39,10 +43,12 @@ static struct mem_shdr *toc_section(consunsigned long my_r2 (const struct mem_ehdr *ehdr) {struct mem_shdr *shdr; + shdr =toc_section (ehdr);if (!shdr) {die ("TOC reloc without a toc section?" ); } +return shdr->sh_addr +0x8000 ; }
@@ -112,14 +118,13 @@ void machine_apply_elf_rel(struct mem_ehcase R_PPC64_REL24 :/* Convert value to relative */ value -= address; -if (value +0x2000000 >0x3ffffff || (value &3 ) !=0 ){ -die ("REL24 %li out of range!\n" , - (long int )value); +if (value +0x2000000 >0x3ffffff || (value &3 ) !=0 ) { +die ("REL24 %li out of range!\n" , (long int )value); }/* Only replace bits 2 through 26 */ - *(uint32_t *)location = (*(uint32_t *)location & ~0x03fffffc ) - | (value &0x03fffffc ); + *(uint32_t *)location = (*(uint32_t *)location & ~0x03fffffc ) | + (value &0x03fffffc );break ;case R_PPC64_ADDR16_LO :
@@ -127,23 +132,23 @@ void machine_apply_elf_rel(struct mem_ehbreak ;case R_PPC64_ADDR16_HI : - *(uint16_t *)location = (value>>16 ) &0xffff ; + *(uint16_t *)location = (value >>16 ) &0xffff ;break ;case R_PPC64_ADDR16_HA : - *(uint16_t *)location = (((value+0x8000 )>>16 ) &0xffff ); + *(uint16_t *)location = (((value +0x8000 ) >>16 ) &0xffff );break ; -case R_PPC64_ADDR16_HIGHEST : - *(uint16_t *)location = (((uint64_t )value>>48 ) &0xffff ); -break ;case R_PPC64_ADDR16_HIGHER : - *(uint16_t *)location = (((uint64_t )value>>32 ) &0xffff ); + *(uint16_t *)location = (((uint64_t )value >>32 ) &0xffff ); +break ; + +case R_PPC64_ADDR16_HIGHEST : + *(uint16_t *)location = (((uint64_t )value >>48 ) &0xffff );break ;default :die ("Unknown rela relocation: %lu\n" , r_type);break ; } -return ; }
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 4 lines · Anton Blanchard
commit
46b2d0b8a719(kexec/powerpc fix optimization for size (gcc -Os) build) added out of line GPR save/restore handlers for 32bit -Os builds. This patch adds the handlers for 64bit builds.
The linker is supposed to add these functions magically on final link for powerpc64. Um, I suppose you're doing something horrible with kexec, ld -r instead of normal final link at a guess?
Signature · 7 lines
Alan Modra Australia Development Lab, IBM _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hi Alan,
Quoted 7 lines
Review
Quoted 3 lines
commit
46b2d0b8a719(kexec/powerpc fix optimization for size (gcc(quoted diff) +0
-2-Os) build) added out of line GPR save/restore handlers for 32bit -Os builds. This patch adds the handlers for 64bit builds.The linker is supposed to add these functions magically on final link for powerpc64. Um, I suppose you're doing something horrible with kexec, ld -r instead of normal final link at a guess?
Yeah:
gcc -g -O2 -fno-strict-aliasing -Wall -Wstrict-prototypes -fno-zero-initialized-in-bss -m64 -Os -fno-builtin -ffreestanding -m64 -Wl,--no-undefined -nostartfiles -nostdlib -nodefaultlibs -e purgatory_start -r -o purgatory/purgatory.ro purgatory/purgatory.o purgatory/printf.o purgatory/string.o purgatory/arch/ppc64/v2wrap.o purgatory/arch/ppc64/hvCall.o purgatory/arch/ppc64/purgatory-ppc64.o purgatory/arch/ppc64/console-ppc64.o purgatory/arch/ppc64/crashdump_backup.o purgatory/arch/ppc64/misc.o purgatory/sha256.o
bin/bin-to-hex purgatory < purgatory/purgatory.ro > kexec/purgatory.c
I wonder why we aren't building and linking an -fpic object, wouldn't it make the relocation code much simpler?
Anton
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 2 lines · Anton Blanchard
I wonder why we aren't building and linking an -fpic object, wouldn't it make the relocation code much simpler?
No, powerpc64 is PIC anyway.
Signature · 7 lines
Alan Modra Australia Development Lab, IBM _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 5 lines · Alan Modra
Quoted 2 lines · Anton Blanchard
I wonder why we aren't building and linking an -fpic object, wouldn't it make the relocation code much simpler?
No, powerpc64 is PIC anyway.
Hi Alan, Hi Anton, Hi all,
I am wondering if you are comfortable with me (finally) releasing a new version of kexec-tools with this series of patches applied.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi Horms,
Quoted 4 lines
Hi Alan, Hi Anton, Hi all,
I am wondering if you are comfortable with me (finally) releasing a new version of kexec-tools with this series of patches applied.
Sorry for taking a while to get back to you. I haven't found any more bugs on the ppc64 side, so I'm definitely comfortable (from a ppc64 perspective).
Anton
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec