Fri Feb 18 06:43:00 2022 UTC ()
Don't crash when reporting an undefined symbol.


(mlelstv)
diff -r1.20 -r1.21 src/sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c

cvs diff -r1.20 -r1.21 src/sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c (expand / switch to unified diff)

--- src/sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c 2021/05/18 20:34:20 1.20
+++ src/sys/arch/amiga/stand/bootblock/elf2bb/elf2bb.c 2022/02/18 06:42:59 1.21
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: elf2bb.c,v 1.20 2021/05/18 20:34:20 dholland Exp $ */ 1/* $NetBSD: elf2bb.c,v 1.21 2022/02/18 06:42:59 mlelstv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1996,2006 The NetBSD Foundation, Inc. 4 * Copyright (c) 1996,2006 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 Ignatios Souvatzis. 8 * by Ignatios Souvatzis.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -315,27 +315,27 @@ retry: @@ -315,27 +315,27 @@ retry:
315 break; 315 break;
316 } 316 }
317 if (base == NULL) 317 if (base == NULL)
318 errx(1, "Can't find section for reloc %s", shstrtab + 318 errx(1, "Can't find section for reloc %s", shstrtab +
319 htobe32(sh[i].sh_name)); 319 htobe32(sh[i].sh_name));
320 ra = (Elf32_Rela *)(image + htobe32(sh[i].sh_offset)); 320 ra = (Elf32_Rela *)(image + htobe32(sh[i].sh_offset));
321 for (n = 0; n < htobe32(sh[i].sh_size); n += sizeof(Elf32_Rela), ++ra) { 321 for (n = 0; n < htobe32(sh[i].sh_size); n += sizeof(Elf32_Rela), ++ra) {
322 Elf32_Sym *s; 322 Elf32_Sym *s;
323 int value; 323 int value;
324 324
325 s = &symtab[ELF32_R_SYM(htobe32(ra->r_info))]; 325 s = &symtab[ELF32_R_SYM(htobe32(ra->r_info))];
326 if (s->st_shndx == ELF_SYM_UNDEFINED) { 326 if (s->st_shndx == ELF_SYM_UNDEFINED) {
327 fprintf(stderr, "Undefined symbol: %s\n", 327 fprintf(stderr, "Undefined symbol: %s\n",
328 strtab + s->st_name); 328 strtab + htobe32(s->st_name));
329 ++undefsyms; 329 ++undefsyms;
330 } 330 }
331 value = htobe32(ra->r_addend) + eval(s, sect_offset); 331 value = htobe32(ra->r_addend) + eval(s, sect_offset);
332 dprintf(("reloc %04x info %04x (type %d sym %d) add 0x%x val %x\n", 332 dprintf(("reloc %04x info %04x (type %d sym %d) add 0x%x val %x\n",
333 htobe32(ra->r_offset), htobe32(ra->r_info), 333 htobe32(ra->r_offset), htobe32(ra->r_info),
334 ELF32_R_TYPE(htobe32(ra->r_info)), 334 ELF32_R_TYPE(htobe32(ra->r_info)),
335 ELF32_R_SYM(htobe32(ra->r_info)), 335 ELF32_R_SYM(htobe32(ra->r_info)),
336 htobe32(ra->r_addend), value)); 336 htobe32(ra->r_addend), value));
337 switch (ELF32_R_TYPE(htobe32(ra->r_info))) { 337 switch (ELF32_R_TYPE(htobe32(ra->r_info))) {
338 case R_68K_32: 338 case R_68K_32:
339 tmp32 = htobe32(value); 339 tmp32 = htobe32(value);
340 memcpy(base + htobe32(ra->r_offset), &tmp32, 340 memcpy(base + htobe32(ra->r_offset), &tmp32,
341 sizeof(tmp32)); 341 sizeof(tmp32));