[PATCH] D29714: [ELF] - Do sign extend for addends of R_386_8, R_386_16 relocations

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 8 06:09:52 PST 2017


Are you sure these are sign extended? That is unexpected given the names.

George Rimar via Phabricator <reviews at reviews.llvm.org> writes:

> grimar created this revision.
>
> The same we did earlier for PC ones,
> currenly LLD fails to link kernel, reporting relocation out of range because of this.
>
> I prepared separate test, because had to involve -Ttext option and
> that would change currect pc8/pc16 test significantly , what probably not worth to do.
>
>
> https://reviews.llvm.org/D29714
>
> Files:
>   ELF/Target.cpp
>   test/ELF/i386-reloc8-reloc16-addend.s
>
>
> Index: test/ELF/i386-reloc8-reloc16-addend.s
> ===================================================================
> --- test/ELF/i386-reloc8-reloc16-addend.s
> +++ test/ELF/i386-reloc8-reloc16-addend.s
> @@ -0,0 +1,17 @@
> +# REQUIRES: x86
> +# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux-gnu %s -o %t1.o
> +
> +# RUN: ld.lld -Ttext=0x0 %t1.o -o %t.out
> +# RUN: llvm-objdump -s -t %t.out | FileCheck %s
> +# CHECK:      Contents of section .text:
> +# CHECK-NEXT:  0000 020100 
> +## 0x3 + addend(-1) = 0x02
> +## 0x3 + addend(-2) = 0x0100
> +# CHECK: SYMBOL TABLE:
> +# CHECK: 00000003 .und
> +
> +.byte  und-1
> +.short und-2
> +
> +.section .und, "ax"
> +und:
> Index: ELF/Target.cpp
> ===================================================================
> --- ELF/Target.cpp
> +++ ELF/Target.cpp
> @@ -491,11 +491,9 @@
>    default:
>      return 0;
>    case R_386_8:
> -    return *Buf;
>    case R_386_PC8:
>      return SignExtend64<8>(*Buf);
>    case R_386_16:
> -    return read16le(Buf);
>    case R_386_PC16:
>      return SignExtend64<16>(read16le(Buf));
>    case R_386_32:
>
>
> Index: test/ELF/i386-reloc8-reloc16-addend.s
> ===================================================================
> --- test/ELF/i386-reloc8-reloc16-addend.s
> +++ test/ELF/i386-reloc8-reloc16-addend.s
> @@ -0,0 +1,17 @@
> +# REQUIRES: x86
> +# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux-gnu %s -o %t1.o
> +
> +# RUN: ld.lld -Ttext=0x0 %t1.o -o %t.out
> +# RUN: llvm-objdump -s -t %t.out | FileCheck %s
> +# CHECK:      Contents of section .text:
> +# CHECK-NEXT:  0000 020100 
> +## 0x3 + addend(-1) = 0x02
> +## 0x3 + addend(-2) = 0x0100
> +# CHECK: SYMBOL TABLE:
> +# CHECK: 00000003 .und
> +
> +.byte  und-1
> +.short und-2
> +
> +.section .und, "ax"
> +und:
> Index: ELF/Target.cpp
> ===================================================================
> --- ELF/Target.cpp
> +++ ELF/Target.cpp
> @@ -491,11 +491,9 @@
>    default:
>      return 0;
>    case R_386_8:
> -    return *Buf;
>    case R_386_PC8:
>      return SignExtend64<8>(*Buf);
>    case R_386_16:
> -    return read16le(Buf);
>    case R_386_PC16:
>      return SignExtend64<16>(read16le(Buf));
>    case R_386_32:


More information about the llvm-commits mailing list