diff --git a/arch/arm/src/arm/up_elf.c b/arch/arm/src/arm/up_elf.c index 433024b849..e46703563d 100644 --- a/arch/arm/src/arm/up_elf.c +++ b/arch/arm/src/arm/up_elf.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/arm/up_elf.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -132,6 +132,10 @@ bool up_checkarch(FAR const Elf32_Ehdr *ehdr) * Input Parameters: * rel - The relocation type * sym - The ELF symbol structure containing the fully resolved value. + * There are a few relocation types for a few architectures that do + * not require symbol information. For those, this value will be + * NULL. Implementations of these functions must be able to handle + * that case. * addr - The address that requires the relocation. * * Returned Value: @@ -144,8 +148,19 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, uintptr_t addr) { int32_t offset; + unsigned int relotype; - switch (ELF32_R_TYPE(rel->r_info)) + /* All relocations depend upon having valid symbol information */ + + relotype = ELF32_R_TYPE(rel->r_info); + if (sym == NULL && relotype != R_ARM_NONE) + { + return -EINVAL; + } + + /* Handle the relocation by relocation type */ + + switch (relotype) { case R_ARM_NONE: { @@ -254,4 +269,3 @@ int up_relocateadd(FAR const Elf32_Rela *rel, FAR const Elf32_Sym *sym, bdbg("RELA relocation not supported\n"); return -ENOSYS; } - diff --git a/arch/arm/src/armv6-m/up_elf.c b/arch/arm/src/armv6-m/up_elf.c index 7c5b76c21b..d4529540ad 100644 --- a/arch/arm/src/armv6-m/up_elf.c +++ b/arch/arm/src/armv6-m/up_elf.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/armv6-m/up_elf.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -124,6 +124,10 @@ bool up_checkarch(FAR const Elf32_Ehdr *ehdr) * Input Parameters: * rel - The relocation type * sym - The ELF symbol structure containing the fully resolved value. + * There are a few relocation types for a few architectures that do + * not require symbol information. For those, this value will be + * NULL. Implementations of these functions must be able to handle + * that case. * addr - The address that requires the relocation. * * Returned Value: @@ -138,8 +142,21 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, int32_t offset; uint32_t upper_insn; uint32_t lower_insn; + unsigned int relotype; - switch (ELF32_R_TYPE(rel->r_info)) + /* All relocations except R_ARM_V4BX depend upon having valid symbol + * information. + */ + + relotype = ELF32_R_TYPE(rel->r_info); + if (sym == NULL && relotype != R_ARM_NONE && relotype != R_ARM_V4BX) + { + return -EINVAL; + } + + /* Handle the relocation by relocation type */ + + switch (relotype) { case R_ARM_NONE: { @@ -447,4 +464,3 @@ int up_relocateadd(FAR const Elf32_Rela *rel, FAR const Elf32_Sym *sym, bdbg("RELA relocation not supported\n"); return -ENOSYS; } - diff --git a/arch/arm/src/armv7-a/arm_elf.c b/arch/arm/src/armv7-a/arm_elf.c index 0075f2e2a0..97b85620f2 100644 --- a/arch/arm/src/armv7-a/arm_elf.c +++ b/arch/arm/src/armv7-a/arm_elf.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/armv-7a/arm_elf.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -132,6 +132,10 @@ bool up_checkarch(FAR const Elf32_Ehdr *ehdr) * Input Parameters: * rel - The relocation type * sym - The ELF symbol structure containing the fully resolved value. + * There are a few relocation types for a few architectures that do + * not require symbol information. For those, this value will be + * NULL. Implementations of these functions must be able to handle + * that case. * addr - The address that requires the relocation. * * Returned Value: @@ -144,8 +148,21 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, uintptr_t addr) { int32_t offset; + unsigned int relotype; - switch (ELF32_R_TYPE(rel->r_info)) + /* All relocations except R_ARM_V4BX depend upon having valid symbol + * information. + */ + + relotype = ELF32_R_TYPE(rel->r_info); + if (sym == NULL && relotype != R_ARM_NONE && relotype != R_ARM_V4BX) + { + return -EINVAL; + } + + /* Handle the relocation by relocation type */ + + switch (relotype) { case R_ARM_NONE: { @@ -254,4 +271,3 @@ int up_relocateadd(FAR const Elf32_Rela *rel, FAR const Elf32_Sym *sym, bdbg("RELA relocation not supported\n"); return -ENOSYS; } - diff --git a/arch/arm/src/armv7-m/up_elf.c b/arch/arm/src/armv7-m/up_elf.c index c4d30d936b..c1ea4e4941 100644 --- a/arch/arm/src/armv7-m/up_elf.c +++ b/arch/arm/src/armv7-m/up_elf.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/armv7-m/up_elf.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -124,6 +124,10 @@ bool up_checkarch(FAR const Elf32_Ehdr *ehdr) * Input Parameters: * rel - The relocation type * sym - The ELF symbol structure containing the fully resolved value. + * There are a few relocation types for a few architectures that do + * not require symbol information. For those, this value will be + * NULL. Implementations of these functions must be able to handle + * that case. * addr - The address that requires the relocation. * * Returned Value: @@ -138,8 +142,21 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, int32_t offset; uint32_t upper_insn; uint32_t lower_insn; + unsigned int relotype; - switch (ELF32_R_TYPE(rel->r_info)) + /* All relocations except R_ARM_V4BX depend upon having valid symbol + * information. + */ + + relotype = ELF32_R_TYPE(rel->r_info); + if (sym == NULL && relotype != R_ARM_NONE && relotype != R_ARM_V4BX) + { + return -EINVAL; + } + + /* Handle the relocation by relocation type */ + + switch (relotype) { case R_ARM_NONE: { @@ -447,4 +464,3 @@ int up_relocateadd(FAR const Elf32_Rela *rel, FAR const Elf32_Sym *sym, bdbg("RELA relocation not supported\n"); return -ENOSYS; } - diff --git a/arch/sim/src/up_elf.c b/arch/sim/src/up_elf.c index 02b4ce7105..888b09077e 100644 --- a/arch/sim/src/up_elf.c +++ b/arch/sim/src/up_elf.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/sim/src/up_elf.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -100,6 +100,10 @@ bool up_checkarch(FAR const Elf32_Ehdr *hdr) * Input Parameters: * rel - The relocation type * sym - The ELF symbol structure containing the fully resolved value. + * There are a few relocation types for a few architectures that do + * not require symbol information. For those, this value will be + * NULL. Implementations of these functions must be able to handle + * that case. * addr - The address that requires the relocation. * * Returned Value: @@ -113,6 +117,15 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, { FAR uint32_t *ptr = (FAR uint32_t *)addr; + /* All relocations depend upon having valid symbol information. */ + + if (sym == NULL) + { + return -EINVAL; + } + + /* Handle the relocation by relocation type */ + switch (ELF32_R_TYPE(rel->r_info)) { case R_386_32: @@ -124,7 +137,7 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, break; default: - return -EINVAL; + return -EINVAL; } return OK; diff --git a/arch/x86/src/common/up_elf.c b/arch/x86/src/common/up_elf.c index 7c5772a9bb..894f865786 100644 --- a/arch/x86/src/common/up_elf.c +++ b/arch/x86/src/common/up_elf.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/x86/src/up_elf.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -100,6 +100,10 @@ bool up_checkarch(FAR const Elf32_Ehdr *hdr) * Input Parameters: * rel - The relocation type * sym - The ELF symbol structure containing the fully resolved value. + * There are a few relocation types for a few architectures that do + * not require symbol information. For those, this value will be + * NULL. Implementations of these functions must be able to handle + * that case. * addr - The address that requires the relocation. * * Returned Value: @@ -113,6 +117,15 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, { FAR uint32_t *ptr = (FAR uint32_t *)addr; + /* All relocations depend upon having valid symbol information. */ + + if (sym == NULL) + { + return -EINVAL; + } + + /* Handle the relocation by relocation type */ + switch (ELF32_R_TYPE(rel->r_info)) { case R_386_32: @@ -124,7 +137,7 @@ int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, break; default: - return -EINVAL; + return -EINVAL; } return OK;