[lld] r225082 - ReaderWriter: teach the writer about IMAGE_REL_ARM_BRANCH24T

Jean-Daniel Dupas dev at xenonium.com
Sat Jan 3 01:28:34 PST 2015


Hi,

I don’t know if other fell the same, but I find it easier to check lld commits that affect all archs when arch/object specific commits are prefixed ( [PECOFF] ReaderWriter: … )


> Le 2 janv. 2015 à 19:52, Saleem Abdulrasool <compnerd at compnerd.org> a écrit :
> 
> Author: compnerd
> Date: Fri Jan  2 12:51:59 2015
> New Revision: 225082
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=225082&view=rev
> Log:
> ReaderWriter: teach the writer about IMAGE_REL_ARM_BRANCH24T
> 
> This adds support for IMAGE_REL_ARM_BRANCH24T relocations.  Similar to the
> IMAGE_REL_ARM_BLX32T relocation, this relocation requires munging an
> instruction.  The instruction encoding is quite similar, allowing us to reuse
> the same munging implementation.  This is needed by the entry point stubs for
> modules provided by MSVCRT.
> 
> Added:
>  lld/trunk/test/pecoff/Inputs/armnt-branch24t.obj.yaml
>  lld/trunk/test/pecoff/Inputs/armnt-branch24t.s
>  lld/trunk/test/pecoff/armnt-branch24t.test
> Modified:
>  lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
> 
> Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=225082&r1=225081&r2=225082&view=diff
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Fri Jan  2 12:51:59 2015
> @@ -561,10 +561,12 @@ static void applyThumbMoveImmediate(ulit
> static void applyThumbBranchImmediate(ulittle16_t *bl, int32_t imm) {
> // BL(T1):  |11110|S|imm10|11|J1|1|J2|imm11|
> //          imm32 = sext S:I1:I2:imm10:imm11:'0'
> +  // B.W(T4): |11110|S|imm10|10|J1|1|J2|imm11|
> +  //          imm32 = sext S:I1:I2:imm10:imm11:'0'
> //
> //          I1 = ~(J1 ^ S), I2 = ~(J2 ^ S)
> 
> -  assert((~abs(imm) & (-1 << 24)) && "bl out of range");
> +  assert((~abs(imm) & (-1 << 24)) && "bl/b.w out of range");
> 
> uint32_t S = (imm < 0 ? 1 : 0);
> uint32_t J1 = ((~imm & 0x00800000) >> 23) ^ S;
> @@ -602,6 +604,10 @@ void AtomChunk::applyRelocationsARM(uint
>       applyThumbMoveImmediate(&RelocSite16[0], (TargetAddr + ImageBase) >>  0);
>       applyThumbMoveImmediate(&RelocSite16[2], (TargetAddr + ImageBase) >> 16);
>       break;
> +      case llvm::COFF::IMAGE_REL_ARM_BRANCH24T:
> +        applyThumbBranchImmediate(RelocSite16,
> +                                  TargetAddr - AtomRVA[Atom] - AtomOffset - 4);
> +        break;
>     case llvm::COFF::IMAGE_REL_ARM_BLX23T:
>       applyThumbBranchImmediate(RelocSite16,
>                                 TargetAddr - AtomRVA[Atom] - AtomOffset - 4);
> 
> Added: lld/trunk/test/pecoff/Inputs/armnt-branch24t.obj.yaml
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/armnt-branch24t.obj.yaml?rev=225082&view=auto
> ==============================================================================
> --- lld/trunk/test/pecoff/Inputs/armnt-branch24t.obj.yaml (added)
> +++ lld/trunk/test/pecoff/Inputs/armnt-branch24t.obj.yaml Fri Jan  2 12:51:59 2015
> @@ -0,0 +1,39 @@
> +---
> +header:
> +  Machine:         IMAGE_FILE_MACHINE_ARMNT
> +  Characteristics: [  ]
> +sections:
> +  - Name:            .text
> +    Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
> +    Alignment:       4
> +    SectionData:     704700BF202000F000B8
> +    Relocations:
> +      - VirtualAddress:  6
> +        SymbolName:      identity
> +        Type:            20
> +symbols:
> +  - Name:            .text
> +    Value:           0
> +    SectionNumber:   1
> +    SimpleType:      IMAGE_SYM_TYPE_NULL
> +    ComplexType:     IMAGE_SYM_DTYPE_NULL
> +    StorageClass:    IMAGE_SYM_CLASS_STATIC
> +    SectionDefinition: 
> +      Length:          10
> +      NumberOfRelocations: 1
> +      NumberOfLinenumbers: 0
> +      CheckSum:        0
> +      Number:          1
> +  - Name:            identity
> +    Value:           0
> +    SectionNumber:   1
> +    SimpleType:      IMAGE_SYM_TYPE_NULL
> +    ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
> +    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
> +  - Name:            function
> +    Value:           4
> +    SectionNumber:   1
> +    SimpleType:      IMAGE_SYM_TYPE_NULL
> +    ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
> +    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
> +...
> 
> Added: lld/trunk/test/pecoff/Inputs/armnt-branch24t.s
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/armnt-branch24t.s?rev=225082&view=auto
> ==============================================================================
> --- lld/trunk/test/pecoff/Inputs/armnt-branch24t.s (added)
> +++ lld/trunk/test/pecoff/Inputs/armnt-branch24t.s Fri Jan  2 12:51:59 2015
> @@ -0,0 +1,27 @@
> +
> +@ int ___declspec(noinline) identity(int i) { return i; }
> +@ int function(void) { return identity(32); }
> +
> +	.syntax unified
> +	.thumb
> +	.text
> +
> +	.def identity
> +		.scl 2
> +		.type 32
> +	.endef
> +	.global identity
> +	.align 2
> +	.code16
> +	.thumb_func
> +identity:
> +	bx lr
> +
> +	.def function
> +		.scl 2
> +		.type 32
> +	.endef
> +function:
> +	movs r0, #32
> +	b identity
> +
> 
> Added: lld/trunk/test/pecoff/armnt-branch24t.test
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/armnt-branch24t.test?rev=225082&view=auto
> ==============================================================================
> --- lld/trunk/test/pecoff/armnt-branch24t.test (added)
> +++ lld/trunk/test/pecoff/armnt-branch24t.test Fri Jan  2 12:51:59 2015
> @@ -0,0 +1,18 @@
> +# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-branch24t.obj.yaml
> +# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE
> +# RUN: lld -flavor link /entry:function /subsystem:console /out:%t.exe %t.obj
> +# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER
> +
> +BEFORE: Disassembly of section .text:
> +BEFORE:        0: 70 47         bx lr
> +BEFORE:        2: 00 bf         nop
> +BEFORE:        4: 20 20         movs r0, #32
> +BEFORE:        6: 00 f0 00 b8   b.w #0
> +
> +AFTER: Disassembly of section .text:
> +AFTER: .text:
> +AFTER:     1000: 70 47         bx lr
> +AFTER:     1002: 00 bf         nop
> +AFTER:     1004: 20 20         movs r0, #32
> +AFTER:     1006: ff f7 fb bf   b.w #-10
> +
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list