r241102 - CodeGen: Assign an appropriate comdat to thunks.

Alexey Samsonov vonosmas at gmail.com
Tue Jun 30 14:46:58 PDT 2015


Could it cause this use-after-free reported by ASan?

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/5169/steps/check-clang%20asan/logs/stdio

On Tue, Jun 30, 2015 at 1:19 PM, Peter Collingbourne <peter at pcc.me.uk>
wrote:

> This looks more like r241103. David is working on a fix.
>
> On Tue, Jun 30, 2015 at 01:10:13PM -0700, Nico Weber wrote:
> > It looks like this breaks building base.dll in the Chromium project:
> > http://code.google.com/p/chromium/issues/detail?id=505916
> >
> > On Tue, Jun 30, 2015 at 12:07 PM, Peter Collingbourne <peter at pcc.me.uk>
> > wrote:
> >
> > > Author: pcc
> > > Date: Tue Jun 30 14:07:26 2015
> > > New Revision: 241102
> > >
> > > URL: http://llvm.org/viewvc/llvm-project?rev=241102&view=rev
> > > Log:
> > > CodeGen: Assign an appropriate comdat to thunks.
> > >
> > > Previously we were not assigning a comdat to thunks in the Microsoft
> ABI,
> > > which would have required us to emit these functions outside of a
> comdat.
> > > (Due to an inconsistency in how we were emitting objects, we were
> getting
> > > this
> > > right most of the time, but only when compiling with function
> sections.)
> > > This
> > > code generator change causes us to create a comdat for each thunk.
> > >
> > > Differential Revision: http://reviews.llvm.org/D10829
> > >
> > > Modified:
> > >     cfe/trunk/lib/CodeGen/CGVTables.cpp
> > >     cfe/trunk/test/CodeGenCXX/microsoft-abi-thunks.cpp
> > >
> > > Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
> > > URL:
> > >
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=241102&r1=241101&r2=241102&view=diff
> > >
> > >
> ==============================================================================
> > > --- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
> > > +++ cfe/trunk/lib/CodeGen/CGVTables.cpp Tue Jun 30 14:07:26 2015
> > > @@ -378,9 +378,6 @@ void CodeGenFunction::GenerateThunk(llvm
> > >    // Set the right linkage.
> > >    CGM.setFunctionLinkage(GD, Fn);
> > >
> > > -  if (CGM.supportsCOMDAT() && Fn->isWeakForLinker())
> > > -    Fn->setComdat(CGM.getModule().getOrInsertComdat(Fn->getName()));
> > > -
> > >    // Set the right visibility.
> > >    const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
> > >    setThunkVisibility(CGM, MD, Thunk, Fn);
> > > @@ -450,17 +447,18 @@ void CodeGenVTables::emitThunk(GlobalDec
> > >      // expensive/sucky at the moment, so don't generate the thunk
> unless
> > >      // we have to.
> > >      // FIXME: Do something better here; GenerateVarArgsThunk is
> extremely
> > > ugly.
> > > -    if (!UseAvailableExternallyLinkage) {
> > > -      CodeGenFunction(CGM).GenerateVarArgsThunk(ThunkFn, FnInfo, GD,
> > > Thunk);
> > > -      CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable, GD,
> > > -                                      !Thunk.Return.isEmpty());
> > > -    }
> > > +    if (UseAvailableExternallyLinkage)
> > > +      return;
> > > +    CodeGenFunction(CGM).GenerateVarArgsThunk(ThunkFn, FnInfo, GD,
> Thunk);
> > >    } else {
> > >      // Normal thunk body generation.
> > >      CodeGenFunction(CGM).GenerateThunk(ThunkFn, FnInfo, GD, Thunk);
> > > -    CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable, GD,
> > > -                                    !Thunk.Return.isEmpty());
> > >    }
> > > +
> > > +  CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable, GD,
> > > +                                  !Thunk.Return.isEmpty());
> > > +  if (CGM.supportsCOMDAT() && ThunkFn->isWeakForLinker())
> > > +
> > >
> ThunkFn->setComdat(CGM.getModule().getOrInsertComdat(ThunkFn->getName()));
> > >  }
> > >
> > >  void CodeGenVTables::maybeEmitThunkForVTable(GlobalDecl GD,
> > >
> > > Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-thunks.cpp
> > > URL:
> > >
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-thunks.cpp?rev=241102&r1=241101&r2=241102&view=diff
> > >
> > >
> ==============================================================================
> > > --- cfe/trunk/test/CodeGenCXX/microsoft-abi-thunks.cpp (original)
> > > +++ cfe/trunk/test/CodeGenCXX/microsoft-abi-thunks.cpp Tue Jun 30
> 14:07:26
> > > 2015
> > > @@ -91,7 +91,7 @@ struct E : D {
> > >
> > >  E::E() {}  // Emits vftable and forces thunk generation.
> > >
> > > -// CODEGEN-LABEL: define weak_odr x86_thiscallcc %struct.C*
> @"\01?goo at E
> > > @@QAEPAUB@@XZ"
> > > +// CODEGEN-LABEL: define weak_odr x86_thiscallcc %struct.C*
> @"\01?goo at E
> > > @@QAEPAUB@@XZ"{{.*}} comdat
> > >  // CODEGEN:   call x86_thiscallcc %struct.C* @"\01?goo at E@@UAEPAUC@
> @XZ"
> > >  // CODEGEN:   getelementptr inbounds i8, i8* {{.*}}, i32 4
> > >  // CODEGEN: ret
> > > @@ -124,7 +124,7 @@ struct I : D {
> > >
> > >  I::I() {}  // Emits vftable and forces thunk generation.
> > >
> > > -// CODEGEN-LABEL: define weak_odr x86_thiscallcc %struct.{{[BF]}}*
> > > @"\01?goo at I@@QAEPAUB@@XZ"
> > > +// CODEGEN-LABEL: define weak_odr x86_thiscallcc %struct.{{[BF]}}*
> > > @"\01?goo at I@@QAEPAUB@@XZ"{{.*}} comdat
> > >  // CODEGEN: %[[ORIG_RET:.*]] = call x86_thiscallcc %struct.F*
> @"\01?goo at I
> > > @@UAEPAUF@@XZ"
> > >  // CODEGEN: %[[ORIG_RET_i8:.*]] = bitcast %struct.F* %[[ORIG_RET]] to
> i8*
> > >  // CODEGEN: %[[VBPTR_i8:.*]] = getelementptr inbounds i8, i8*
> > > %[[ORIG_RET_i8]], i32 4
> > >
> > >
> > > _______________________________________________
> > > cfe-commits mailing list
> > > cfe-commits at cs.uiuc.edu
> > > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> > >
>
> --
> Peter
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



-- 
Alexey Samsonov
vonosmas at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150630/a6f2c640/attachment.html>


More information about the cfe-commits mailing list