| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: loadfile_elf32.c,v 1.52 2017/12/21 14:28:39 maxv Exp $ */ | | 1 | /* $NetBSD: loadfile_elf32.c,v 1.53 2018/08/23 17:35:42 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1997, 2008, 2017 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1997, 2008, 2017 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | | 8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, |
9 | * NASA Ames Research Center, by Christos Zoulas, and by Maxime Villard. | | 9 | * NASA Ames Research Center, by Christos Zoulas, and by Maxime Villard. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
| @@ -246,27 +246,27 @@ externalize_shdr(Elf_Byte bo, Elf_Shdr * | | | @@ -246,27 +246,27 @@ externalize_shdr(Elf_Byte bo, Elf_Shdr * |
246 | * Byte swapping is never necessary in the _STANDALONE case because | | 246 | * Byte swapping is never necessary in the _STANDALONE case because |
247 | * we are being built with the target compiler. | | 247 | * we are being built with the target compiler. |
248 | */ | | 248 | */ |
249 | #define internalize_ehdr(bo, ehdr) /* nothing */ | | 249 | #define internalize_ehdr(bo, ehdr) /* nothing */ |
250 | #define externalize_ehdr(bo, ehdr) /* nothing */ | | 250 | #define externalize_ehdr(bo, ehdr) /* nothing */ |
251 | | | 251 | |
252 | #define internalize_phdr(bo, phdr) /* nothing */ | | 252 | #define internalize_phdr(bo, phdr) /* nothing */ |
253 | | | 253 | |
254 | #define internalize_shdr(bo, shdr) /* nothing */ | | 254 | #define internalize_shdr(bo, shdr) /* nothing */ |
255 | #define externalize_shdr(bo, shdr) /* nothing */ | | 255 | #define externalize_shdr(bo, shdr) /* nothing */ |
256 | #endif /* _STANDALONE */ | | 256 | #endif /* _STANDALONE */ |
257 | | | 257 | |
258 | #define IS_TEXT(p) (p.p_flags & PF_X) | | 258 | #define IS_TEXT(p) (p.p_flags & PF_X) |
259 | #define IS_DATA(p) (p.p_flags & PF_W) | | 259 | #define IS_DATA(p) ((p.p_flags & PF_X) == 0) |
260 | #define IS_BSS(p) (p.p_filesz < p.p_memsz) | | 260 | #define IS_BSS(p) (p.p_filesz < p.p_memsz) |
261 | | | 261 | |
262 | #ifndef MD_LOADSEG /* Allow processor ABI specific segment loads */ | | 262 | #ifndef MD_LOADSEG /* Allow processor ABI specific segment loads */ |
263 | #define MD_LOADSEG(a) /*CONSTCOND*/0 | | 263 | #define MD_LOADSEG(a) /*CONSTCOND*/0 |
264 | #endif | | 264 | #endif |
265 | | | 265 | |
266 | /* -------------------------------------------------------------------------- */ | | 266 | /* -------------------------------------------------------------------------- */ |
267 | | | 267 | |
268 | #define KERNALIGN_SMALL (1 << 12) /* XXX should depend on marks[] */ | | 268 | #define KERNALIGN_SMALL (1 << 12) /* XXX should depend on marks[] */ |
269 | #define KERNALIGN_LARGE (1 << 21) /* XXX should depend on marks[] */ | | 269 | #define KERNALIGN_LARGE (1 << 21) /* XXX should depend on marks[] */ |
270 | | | 270 | |
271 | /* | | 271 | /* |
272 | * Read some data from a file, and put it in the bootloader memory (local). | | 272 | * Read some data from a file, and put it in the bootloader memory (local). |
| @@ -698,27 +698,27 @@ ELFNAMEEND(loadfile_static)(int fd, Elf_ | | | @@ -698,27 +698,27 @@ ELFNAMEEND(loadfile_static)(int fd, Elf_ |
698 | ret = ELFNAMEEND(readfile_local)(fd, elf->e_phoff, phdr, sz); | | 698 | ret = ELFNAMEEND(readfile_local)(fd, elf->e_phoff, phdr, sz); |
699 | if (ret == -1) { | | 699 | if (ret == -1) { |
700 | goto freephdr; | | 700 | goto freephdr; |
701 | } | | 701 | } |
702 | | | 702 | |
703 | first = 1; | | 703 | first = 1; |
704 | for (i = 0; i < elf->e_phnum; i++) { | | 704 | for (i = 0; i < elf->e_phnum; i++) { |
705 | internalize_phdr(elf->e_ident[EI_DATA], &phdr[i]); | | 705 | internalize_phdr(elf->e_ident[EI_DATA], &phdr[i]); |
706 | | | 706 | |
707 | if (MD_LOADSEG(&phdr[i])) | | 707 | if (MD_LOADSEG(&phdr[i])) |
708 | goto loadseg; | | 708 | goto loadseg; |
709 | | | 709 | |
710 | if (phdr[i].p_type != PT_LOAD || | | 710 | if (phdr[i].p_type != PT_LOAD || |
711 | (phdr[i].p_flags & (PF_W|PF_X)) == 0) | | 711 | (phdr[i].p_flags & (PF_W|PF_R|PF_X)) == 0) |
712 | continue; | | 712 | continue; |
713 | | | 713 | |
714 | if ((IS_TEXT(phdr[i]) && (flags & LOAD_TEXT)) || | | 714 | if ((IS_TEXT(phdr[i]) && (flags & LOAD_TEXT)) || |
715 | (IS_DATA(phdr[i]) && (flags & LOAD_DATA))) { | | 715 | (IS_DATA(phdr[i]) && (flags & LOAD_DATA))) { |
716 | loadseg: | | 716 | loadseg: |
717 | /* XXX: Assume first address is lowest */ | | 717 | /* XXX: Assume first address is lowest */ |
718 | if (marks[MARK_DATA] == 0 && IS_DATA(phdr[i])) | | 718 | if (marks[MARK_DATA] == 0 && IS_DATA(phdr[i])) |
719 | marks[MARK_DATA] = LOADADDR(phdr[i].p_vaddr); | | 719 | marks[MARK_DATA] = LOADADDR(phdr[i].p_vaddr); |
720 | | | 720 | |
721 | /* Read in segment. */ | | 721 | /* Read in segment. */ |
722 | PROGRESS(("%s%lu", first ? "" : "+", | | 722 | PROGRESS(("%s%lu", first ? "" : "+", |
723 | (u_long)phdr[i].p_filesz)); | | 723 | (u_long)phdr[i].p_filesz)); |
724 | | | 724 | |