r290569 - Driver: switch Windows to static RelocModel

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 28 09:50:24 PST 2016


I filed https://llvm.org/bugs/show_bug.cgi?id=31488 for this.

On Wed, Dec 28, 2016 at 9:37 AM, Reid Kleckner <rnk at google.com> wrote:

> This affected code generation of jump tables from switches. This was the
> assembly difference for a switch when going from PIC to static:
>
> $ cat t.cpp
> void g(int);
> void f(int x) {
>   switch (x) {
>   case 0: g(0); break;
>   case 1: g(1); break;
>   case 2: g(2); break;
>   case 3: g(3); break;
>   case 4: g(4); break;
>   case 5: g(5); break;
>   case 6: g(6); break;
>   case 7: g(7); break;
>   case 8: g(8); break;
>   case 9: g(9); break;
>   }
>   g(10);
> }
>
> $ clang -cc1 t.cpp  -S -o - -munwind-tables -mrelocation-model pic -o pic.s
>
> $ clang -cc1 t.cpp  -S -o - -munwind-tables -mrelocation-model static -o
> static.s
>
> $ diff -u pic.s static.s
> --- pic.s       2016-12-28 09:32:48.190468800 -0800
> +++ static.s    2016-12-28 09:32:53.476899200 -0800
> @@ -21,11 +21,9 @@
>         movq    %rax, 40(%rsp)
>         movq    %rdx, 32(%rsp)
>         ja      .LBB0_11
> -       leaq    .LJTI0_0(%rip), %rax
> -       movq    40(%rsp), %rcx
> -       movslq  (%rax,%rcx,4), %rdx
> -       addq    %rax, %rdx
> -       jmpq    *%rdx
> +       movq    40(%rsp), %rax
> +       movq    .LJTI0_0(,%rax,8), %rcx
> +       jmpq    *%rcx
>  .LBB0_1:
>         xorl    %ecx, %ecx
>         callq   "?g@@YAXH at Z"
> @@ -71,20 +69,21 @@
>         nop
>         addq    $56, %rsp
>         retq
> -       .p2align        2, 0x90
> +       .section        .rdata,"dr"
> +       .p2align        3
>  .LJTI0_0:
> -       .long   .LBB0_1-.LJTI0_0
> -       .long   .LBB0_2-.LJTI0_0
> -       .long   .LBB0_3-.LJTI0_0
> -       .long   .LBB0_4-.LJTI0_0
> -       .long   .LBB0_5-.LJTI0_0
> -       .long   .LBB0_6-.LJTI0_0
> -       .long   .LBB0_7-.LJTI0_0
> -       .long   .LBB0_8-.LJTI0_0
> -       .long   .LBB0_9-.LJTI0_0
> -       .long   .LBB0_10-.LJTI0_0
> +       .quad   .LBB0_1
> +       .quad   .LBB0_2
> +       .quad   .LBB0_3
> +       .quad   .LBB0_4
> +       .quad   .LBB0_5
> +       .quad   .LBB0_6
> +       .quad   .LBB0_7
> +       .quad   .LBB0_8
> +       .quad   .LBB0_9
> +       .quad   .LBB0_10
>         .seh_handlerdata
> -       .text
> +       .section        .rdata,"dr"
>  .Lcfi3:
>         .seh_endproc
>
> I think we actually want the .rdata section, but we probably want to use
> ".long .LBB0_N at IMGREL" jump table entries.
>
> This triggers a latent bug in unwind info emission, because .seh_endproc
> is in the wrong section (.rdata, not .text).
>
> Let's revert, fix the latent bug, make switch lowering do what we want,
> and then re-land.
>
> On Wed, Dec 28, 2016 at 9:10 AM, Reid Kleckner <rnk at google.com> wrote:
>
>> I suspect this broke Win64:
>> http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/1410
>>
>> On Mon, Dec 26, 2016 at 6:20 PM, Saleem Abdulrasool via cfe-commits <
>> cfe-commits at lists.llvm.org> wrote:
>>
>>> Author: compnerd
>>> Date: Mon Dec 26 20:20:35 2016
>>> New Revision: 290569
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=290569&view=rev
>>> Log:
>>> Driver: switch Windows to static RelocModel
>>>
>>> Windows uses PE/COFF which is inherently position independent.  The use
>>> of the PIC model is unnecessary.  In fact, we would generate invalid
>>> code using the ELF PIC model when PIC was enabled previously.  Now that
>>> we no longer accept -fPIC and -fpoc, this switches the internal
>>> representation to the static model to permit us to make PIC modules
>>> invalid when targeting Windows.  This should not change the code
>>> generation, only the internal state management.
>>>
>>> Modified:
>>>     cfe/trunk/lib/Driver/MSVCToolChain.cpp
>>>     cfe/trunk/lib/Driver/ToolChains.cpp
>>>     cfe/trunk/lib/Driver/ToolChains.h
>>>     cfe/trunk/test/Driver/pic.c
>>>
>>> Modified: cfe/trunk/lib/Driver/MSVCToolChain.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/MSV
>>> CToolChain.cpp?rev=290569&r1=290568&r2=290569&view=diff
>>> ============================================================
>>> ==================
>>> --- cfe/trunk/lib/Driver/MSVCToolChain.cpp (original)
>>> +++ cfe/trunk/lib/Driver/MSVCToolChain.cpp Mon Dec 26 20:20:35 2016
>>> @@ -82,18 +82,6 @@ bool MSVCToolChain::IsUnwindTablesDefaul
>>>    return getArch() == llvm::Triple::x86_64;
>>>  }
>>>
>>> -bool MSVCToolChain::isPICDefault() const {
>>> -  return getArch() == llvm::Triple::x86_64;
>>> -}
>>> -
>>> -bool MSVCToolChain::isPIEDefault() const {
>>> -  return false;
>>> -}
>>> -
>>> -bool MSVCToolChain::isPICDefaultForced() const {
>>> -  return getArch() == llvm::Triple::x86_64;
>>> -}
>>> -
>>>  #ifdef USE_WIN32
>>>  static bool readFullStringValue(HKEY hkey, const char *valueName,
>>>                                  std::string &value) {
>>>
>>> Modified: cfe/trunk/lib/Driver/ToolChains.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Too
>>> lChains.cpp?rev=290569&r1=290568&r2=290569&view=diff
>>> ============================================================
>>> ==================
>>> --- cfe/trunk/lib/Driver/ToolChains.cpp (original)
>>> +++ cfe/trunk/lib/Driver/ToolChains.cpp Mon Dec 26 20:20:35 2016
>>> @@ -2880,22 +2880,13 @@ bool Generic_GCC::IsUnwindTablesDefault(
>>>
>>>  bool Generic_GCC::isPICDefault() const {
>>>    switch (getArch()) {
>>> -  case llvm::Triple::x86_64:
>>> -    return getTriple().isOSWindows();
>>> +  default: return false;
>>>    case llvm::Triple::ppc64:
>>>    case llvm::Triple::ppc64le:
>>>      return !getTriple().isOSBinFormatMachO() &&
>>> !getTriple().isMacOSX();
>>> -  default:
>>> -    return false;
>>>    }
>>>  }
>>>
>>> -bool Generic_GCC::isPIEDefault() const { return false; }
>>> -
>>> -bool Generic_GCC::isPICDefaultForced() const {
>>> -  return getArch() == llvm::Triple::x86_64 && getTriple().isOSWindows();
>>> -}
>>> -
>>>  bool Generic_GCC::IsIntegratedAssemblerDefault() const {
>>>    switch (getTriple().getArch()) {
>>>    case llvm::Triple::x86:
>>>
>>> Modified: cfe/trunk/lib/Driver/ToolChains.h
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Too
>>> lChains.h?rev=290569&r1=290568&r2=290569&view=diff
>>> ============================================================
>>> ==================
>>> --- cfe/trunk/lib/Driver/ToolChains.h (original)
>>> +++ cfe/trunk/lib/Driver/ToolChains.h Mon Dec 26 20:20:35 2016
>>> @@ -232,8 +232,8 @@ public:
>>>
>>>    bool IsUnwindTablesDefault() const override;
>>>    bool isPICDefault() const override;
>>> -  bool isPIEDefault() const override;
>>> -  bool isPICDefaultForced() const override;
>>> +  bool isPIEDefault() const override { return false; }
>>> +  bool isPICDefaultForced() const override { return false; }
>>>    bool IsIntegratedAssemblerDefault() const override;
>>>    llvm::opt::DerivedArgList *
>>>    TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef
>>> BoundArch,
>>> @@ -1136,9 +1136,9 @@ public:
>>>
>>>    bool IsIntegratedAssemblerDefault() const override;
>>>    bool IsUnwindTablesDefault() const override;
>>> -  bool isPICDefault() const override;
>>> -  bool isPIEDefault() const override;
>>> -  bool isPICDefaultForced() const override;
>>> +  bool isPICDefault() const override { return false; }
>>> +  bool isPIEDefault() const override { return false; }
>>> +  bool isPICDefaultForced() const override { return false; }
>>>
>>>    void
>>>    AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
>>>
>>> Modified: cfe/trunk/test/Driver/pic.c
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/pi
>>> c.c?rev=290569&r1=290568&r2=290569&view=diff
>>> ============================================================
>>> ==================
>>> --- cfe/trunk/test/Driver/pic.c (original)
>>> +++ cfe/trunk/test/Driver/pic.c Mon Dec 26 20:20:35 2016
>>> @@ -255,9 +255,4 @@
>>>  // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
>>>  // RUN: %clang -c %s -target arm64-linux-android -### 2>&1 \
>>>  // RUN:   | FileCheck %s --check-prefix=CHECK-PIC1
>>> -//
>>> -// On Windows-X64 PIC is enabled by default
>>> -// RUN: %clang -c %s -target x86_64-pc-windows-msvc18.0.0 -### 2>&1 \
>>> -// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
>>> -// RUN: %clang -c %s -target x86_64-pc-windows-gnu -### 2>&1 \
>>> -// RUN:   | FileCheck %s --check-prefix=CHECK-PIC2
>>> +
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161228/bf4d4f60/attachment.html>


More information about the cfe-commits mailing list