[PATCH] D31659: [LLD][ELF] Be more precise about Thumb state bit in ARM thunks

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri May 5 11:18:28 PDT 2017


Testcase?
Peter Smith via Phabricator <reviews at reviews.llvm.org> writes:

> peter.smith created this revision.
> Herald added subscribers: rengolin, aemerson.
>
> When we are able to reuse a Thumb thunk from ARM and vice versa the thumb state bit needs to be set to make sure that the bl is converted to a blx.
>
>
> https://reviews.llvm.org/D31659
>
> Files:
>   ELF/Thunks.cpp
>
>
> Index: ELF/Thunks.cpp
> ===================================================================
> --- ELF/Thunks.cpp
> +++ ELF/Thunks.cpp
> @@ -157,7 +157,7 @@
>  void ThumbV7ABSLongThunk<ELFT>::addSymbols(ThunkSection &IS) {
>    this->ThunkSym = addSyntheticLocal<ELFT>(
>        Saver.save("__Thumbv7ABSLongThunk_" + this->Destination.getName()),
> -      STT_FUNC, this->Offset, size(), &IS);
> +      STT_FUNC, this->Offset | 1, size(), &IS);
>    addSyntheticLocal<ELFT>("$t", STT_NOTYPE, this->Offset, 0, &IS);
>  }
>  
> @@ -206,7 +206,7 @@
>        0x60, 0x47,             //     bx   r12
>    };
>    uint64_t S = getARMThunkDestVA(this->Destination);
> -  uint64_t P = this->ThunkSym->getVA();
> +  uint64_t P = this->ThunkSym->getVA() & ~0x1;
>    memcpy(Buf, Data, sizeof(Data));
>    Target->relocateOne(Buf, R_ARM_THM_MOVW_PREL_NC, S - P - 12);
>    Target->relocateOne(Buf + 4, R_ARM_THM_MOVT_PREL, S - P - 8);
> @@ -216,7 +216,7 @@
>  void ThumbV7PILongThunk<ELFT>::addSymbols(ThunkSection &IS) {
>    this->ThunkSym = addSyntheticLocal<ELFT>(
>        Saver.save("__ThumbV7PILongThunk_" + this->Destination.getName()),
> -      STT_FUNC, this->Offset, size(), &IS);
> +      STT_FUNC, this->Offset | 1, size(), &IS);
>    addSyntheticLocal<ELFT>("$t", STT_NOTYPE, this->Offset, 0, &IS);
>  }
>  
>
>
> Index: ELF/Thunks.cpp
> ===================================================================
> --- ELF/Thunks.cpp
> +++ ELF/Thunks.cpp
> @@ -157,7 +157,7 @@
>  void ThumbV7ABSLongThunk<ELFT>::addSymbols(ThunkSection &IS) {
>    this->ThunkSym = addSyntheticLocal<ELFT>(
>        Saver.save("__Thumbv7ABSLongThunk_" + this->Destination.getName()),
> -      STT_FUNC, this->Offset, size(), &IS);
> +      STT_FUNC, this->Offset | 1, size(), &IS);
>    addSyntheticLocal<ELFT>("$t", STT_NOTYPE, this->Offset, 0, &IS);
>  }
>  
> @@ -206,7 +206,7 @@
>        0x60, 0x47,             //     bx   r12
>    };
>    uint64_t S = getARMThunkDestVA(this->Destination);
> -  uint64_t P = this->ThunkSym->getVA();
> +  uint64_t P = this->ThunkSym->getVA() & ~0x1;
>    memcpy(Buf, Data, sizeof(Data));
>    Target->relocateOne(Buf, R_ARM_THM_MOVW_PREL_NC, S - P - 12);
>    Target->relocateOne(Buf + 4, R_ARM_THM_MOVT_PREL, S - P - 8);
> @@ -216,7 +216,7 @@
>  void ThumbV7PILongThunk<ELFT>::addSymbols(ThunkSection &IS) {
>    this->ThunkSym = addSyntheticLocal<ELFT>(
>        Saver.save("__ThumbV7PILongThunk_" + this->Destination.getName()),
> -      STT_FUNC, this->Offset, size(), &IS);
> +      STT_FUNC, this->Offset | 1, size(), &IS);
>    addSyntheticLocal<ELFT>("$t", STT_NOTYPE, this->Offset, 0, &IS);
>  }
>  


More information about the llvm-commits mailing list