diff mbox series

[RFC,v3,07/12] objtool: Use macros to define arch specific reloc types

Message ID 20220624183238.388144-8-sv@linux.ibm.com (mailing list archive)
State Handled Elsewhere
Headers show
Series objtool: Enable and implement --mcount option on powerpc | expand

Commit Message

Sathvika Vasireddy June 24, 2022, 6:32 p.m. UTC
Make relocation types architecture specific.

Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
---
 tools/objtool/arch/x86/include/arch/elf.h | 2 ++
 tools/objtool/check.c                     | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

Comments

Peter Zijlstra July 4, 2022, 11:14 a.m. UTC | #1
On Sat, Jun 25, 2022 at 12:02:33AM +0530, Sathvika Vasireddy wrote:
> Make relocation types architecture specific.
> 
> Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
> ---
>  tools/objtool/arch/x86/include/arch/elf.h | 2 ++
>  tools/objtool/check.c                     | 2 +-
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/objtool/arch/x86/include/arch/elf.h b/tools/objtool/arch/x86/include/arch/elf.h
> index 69cc4264b28a..ac14987cf687 100644
> --- a/tools/objtool/arch/x86/include/arch/elf.h
> +++ b/tools/objtool/arch/x86/include/arch/elf.h
> @@ -2,5 +2,7 @@
>  #define _OBJTOOL_ARCH_ELF
>  
>  #define R_NONE R_X86_64_NONE
> +#define R_ABS64 R_X86_64_64
> +#define R_ABS32 R_X86_64_32
>  
>  #endif /* _OBJTOOL_ARCH_ELF */
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index 98e869721bc4..88f68269860e 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -834,7 +834,7 @@ static int create_mcount_loc_sections(struct objtool_file *file)
>  		memset(loc, 0, size);
>  
>  		if (elf_add_reloc_to_insn(file->elf, sec, idx,
> -					  R_X86_64_64,
> +					  size == sizeof(u64) ? R_ABS64 : R_ABS32,
>  					  insn->sec, insn->offset))
>  			return -1;
>  

Given cross compiles, should this not also be elf dependent?
Christophe Leroy July 4, 2022, 3:53 p.m. UTC | #2
Le 04/07/2022 à 13:14, Peter Zijlstra a écrit :
> On Sat, Jun 25, 2022 at 12:02:33AM +0530, Sathvika Vasireddy wrote:
>> Make relocation types architecture specific.
>>
>> Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
>> ---
>>   tools/objtool/arch/x86/include/arch/elf.h | 2 ++
>>   tools/objtool/check.c                     | 2 +-
>>   2 files changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/objtool/arch/x86/include/arch/elf.h b/tools/objtool/arch/x86/include/arch/elf.h
>> index 69cc4264b28a..ac14987cf687 100644
>> --- a/tools/objtool/arch/x86/include/arch/elf.h
>> +++ b/tools/objtool/arch/x86/include/arch/elf.h
>> @@ -2,5 +2,7 @@
>>   #define _OBJTOOL_ARCH_ELF
>>   
>>   #define R_NONE R_X86_64_NONE
>> +#define R_ABS64 R_X86_64_64
>> +#define R_ABS32 R_X86_64_32
>>   
>>   #endif /* _OBJTOOL_ARCH_ELF */
>> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
>> index 98e869721bc4..88f68269860e 100644
>> --- a/tools/objtool/check.c
>> +++ b/tools/objtool/check.c
>> @@ -834,7 +834,7 @@ static int create_mcount_loc_sections(struct objtool_file *file)
>>   		memset(loc, 0, size);
>>   
>>   		if (elf_add_reloc_to_insn(file->elf, sec, idx,
>> -					  R_X86_64_64,
>> +					  size == sizeof(u64) ? R_ABS64 : R_ABS32,
>>   					  insn->sec, insn->offset))
>>   			return -1;
>>   
> 
> Given cross compiles, should this not also be elf dependent?

size is elf dependent (From the same series [RFC PATCH v3 03/12] 
objtool: Use target file class size instead of a compiled constant)

R_ABS64 and R_ABS32 are defined in the architecture elf.h, and this is 
the architecture for which you are building your kernel, not the 
architecture you cross compile on.
Peter Zijlstra July 4, 2022, 4:18 p.m. UTC | #3
On Mon, Jul 04, 2022 at 03:53:50PM +0000, Christophe Leroy wrote:
> 
> 
> Le 04/07/2022 à 13:14, Peter Zijlstra a écrit :
> > On Sat, Jun 25, 2022 at 12:02:33AM +0530, Sathvika Vasireddy wrote:
> >> Make relocation types architecture specific.
> >>
> >> Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
> >> ---
> >>   tools/objtool/arch/x86/include/arch/elf.h | 2 ++
> >>   tools/objtool/check.c                     | 2 +-
> >>   2 files changed, 3 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/tools/objtool/arch/x86/include/arch/elf.h b/tools/objtool/arch/x86/include/arch/elf.h
> >> index 69cc4264b28a..ac14987cf687 100644
> >> --- a/tools/objtool/arch/x86/include/arch/elf.h
> >> +++ b/tools/objtool/arch/x86/include/arch/elf.h
> >> @@ -2,5 +2,7 @@
> >>   #define _OBJTOOL_ARCH_ELF
> >>   
> >>   #define R_NONE R_X86_64_NONE
> >> +#define R_ABS64 R_X86_64_64
> >> +#define R_ABS32 R_X86_64_32
> >>   
> >>   #endif /* _OBJTOOL_ARCH_ELF */
> >> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> >> index 98e869721bc4..88f68269860e 100644
> >> --- a/tools/objtool/check.c
> >> +++ b/tools/objtool/check.c
> >> @@ -834,7 +834,7 @@ static int create_mcount_loc_sections(struct objtool_file *file)
> >>   		memset(loc, 0, size);
> >>   
> >>   		if (elf_add_reloc_to_insn(file->elf, sec, idx,
> >> -					  R_X86_64_64,
> >> +					  size == sizeof(u64) ? R_ABS64 : R_ABS32,
> >>   					  insn->sec, insn->offset))
> >>   			return -1;
> >>   
> > 
> > Given cross compiles, should this not also be elf dependent?
> 
> size is elf dependent (From the same series [RFC PATCH v3 03/12] 
> objtool: Use target file class size instead of a compiled constant)
> 
> R_ABS64 and R_ABS32 are defined in the architecture elf.h, and this is 
> the architecture for which you are building your kernel, not the 
> architecture you cross compile on.

Duh. Thanks!
diff mbox series

Patch

diff --git a/tools/objtool/arch/x86/include/arch/elf.h b/tools/objtool/arch/x86/include/arch/elf.h
index 69cc4264b28a..ac14987cf687 100644
--- a/tools/objtool/arch/x86/include/arch/elf.h
+++ b/tools/objtool/arch/x86/include/arch/elf.h
@@ -2,5 +2,7 @@ 
 #define _OBJTOOL_ARCH_ELF
 
 #define R_NONE R_X86_64_NONE
+#define R_ABS64 R_X86_64_64
+#define R_ABS32 R_X86_64_32
 
 #endif /* _OBJTOOL_ARCH_ELF */
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 98e869721bc4..88f68269860e 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -834,7 +834,7 @@  static int create_mcount_loc_sections(struct objtool_file *file)
 		memset(loc, 0, size);
 
 		if (elf_add_reloc_to_insn(file->elf, sec, idx,
-					  R_X86_64_64,
+					  size == sizeof(u64) ? R_ABS64 : R_ABS32,
 					  insn->sec, insn->offset))
 			return -1;