On Wed, Jan 30, 2019 at 05:29:53PM -0500, Brad Smith wrote:
> Pull in the save-args patch from base.

with this llvm change, lang/rust is broken. it is not able to recompile
itself (`cd /usr/ports/lang/rust && make' fail).

if I backout the change on devel/llvm, it build again.
(I am Cc dlg@ as the diff comes from base)

error occurs at end of the build (in first steps, it uses bootstrapper
to build compiler, and later it will use the rustc binary it just
compiled, using llvm libs).

example of errors:
- signal: 11, SIGSEGV: invalid memory reference
- rustc(71476) in free(): bogus pointer (double free?) 0x3c24548b44d88941
- signal: 10, SIGBUS: access to undefined memory
- signal: 6, SIGABRT: process abort signal

A build log is available at 
https://exopi.bsdfrog.org/logs/latest/packages/rust-1.32.0p1.log

it affects only amd64 and not i386 (for aarch64 I dunno).

Any help will be appreciate as I am unsure to have enough background to
understand the changes introduced by -msave-args stuff.

Some comments in the diff anyway. I will do some tests, but as it takes
ages to rebuild llvm and rustc...

Please note that rustc doesn't use -msave-args to my knowledge, so I
am only looking at modified code path in general case.

> Index: patches/patch-lib_Target_X86_X86FrameLowering_cpp
> ===================================================================
> RCS file: 
> /home/cvs/ports/devel/llvm/patches/patch-lib_Target_X86_X86FrameLowering_cpp,v
> retrieving revision 1.3
> diff -u -p -u -p -r1.3 patch-lib_Target_X86_X86FrameLowering_cpp
> --- patches/patch-lib_Target_X86_X86FrameLowering_cpp 28 Jan 2019 06:27:28 
> -0000      1.3
> +++ patches/patch-lib_Target_X86_X86FrameLowering_cpp 30 Jan 2019 19:27:30 
> -0000
> +@@ -1618,20 +1676,6 @@ void X86FrameLowering::emitEpilogue(MachineFunction &M
> +   }
> +   uint64_t SEHStackAllocAmt = NumBytes;
> + 
> +-  if (HasFP) {
> +-    // Pop EBP.
> +-    BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::POP64r : X86::POP32r),
> +-            MachineFramePtr)
> +-        .setMIFlag(MachineInstr::FrameDestroy);
> +-    if (NeedsDwarfCFI) {
> +-      unsigned DwarfStackPtr =
> +-          TRI->getDwarfRegNum(Is64Bit ? X86::RSP : X86::ESP, true);
> +-      BuildCFI(MBB, MBBI, DL, MCCFIInstruction::createDefCfa(
> +-                                  nullptr, DwarfStackPtr, -SlotSize));
> +-      --MBBI;
> +-    }
> +-  }
> +-
> +   MachineBasicBlock::iterator FirstCSPop = MBBI;
> +   // Skip the callee-saved pop instructions.
> +   while (MBBI != MBB.begin()) {
> +@@ -1701,6 +1745,28 @@ void X86FrameLowering::emitEpilogue(MachineFunction &M
> +     --MBBI;
> +   }
> + 
> ++  if (HasFP) {
> ++    MBBI = Terminator;

here, MBBI is explicitly assigned to Terminator. It wasn't the case
before in this code path.

Maybe it should be moved to `if (X86FI->getSaveArgSize())' case only ?

> ++
> ++    if (X86FI->getSaveArgSize()) {
> ++      // LEAVE is effectively mov rbp,rsp; pop rbp
> ++      BuildMI(MBB, MBBI, DL, TII.get(X86::LEAVE64), MachineFramePtr)
> ++        .setMIFlag(MachineInstr::FrameDestroy);
> ++    } else {
> ++      // Pop EBP.
> ++      BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::POP64r : X86::POP32r),
> ++              MachineFramePtr)
> ++          .setMIFlag(MachineInstr::FrameDestroy);
> ++    }
> ++    if (NeedsDwarfCFI) {
> ++      unsigned DwarfStackPtr =
> ++          TRI->getDwarfRegNum(Is64Bit ? X86::RSP : X86::ESP, true);
> ++      BuildCFI(MBB, MBBI, DL, MCCFIInstruction::createDefCfa(
> ++                                  nullptr, DwarfStackPtr, -SlotSize));
> ++      --MBBI;
> ++    }
> ++  }
> ++
> +   // Windows unwinder will not invoke function's exception handler if IP is
> +   // either in prologue or in epilogue.  This behavior causes a problem 
> when a
> +   // call immediately precedes an epilogue, because the return address 
> points
> +@@ -1789,6 +1855,8 @@ int X86FrameLowering::getFrameIndexReference(const Mac
> +            "FPDelta isn't aligned per the Win64 ABI!");
> +   }
> + 
> ++  if (FI >= 0)
> ++    Offset -= X86FI->getSaveArgSize();
> + 
> +   if (TRI->hasBasePointer(MF)) {
> +     assert(HasFP && "VLAs and dynamic stack realign, but no FP?!");
> +@@ -3153,4 +3221,8 @@ void X86FrameLowering::processFunctionBeforeFrameFinal
>     addFrameReference(BuildMI(MBB, MBBI, DL, TII.get(X86::MOV64mi32)),
>                       UnwindHelpFI)
>         .addImm(-2);

-- 
Sebastien Marie

Reply via email to