kovdan01 wrote:

> I think you should be able to avoid constructing the initializer twice if you 
> restructure the code a bit to just construct the global before the call to 
> BuildVTablePointer. I added GlobalVariable::replaceInitializer because I was 
> looking at this review: it lets you construct the global before the 
> initializer, without having to do awkward things with RAUW.

@efriedma-quic Sorry, I'm not sure if I got your point correctly.

The issue with enabling address discrimination for signed vtable pointers is 
that it requires self-references - see, for example, 
llvm/test/CodeGen/AArch64/ptrauth-type-info-vptr-discr.ll:

```
@_ZTI10TestStruct = constant { ptr, ptr } {
  ptr ptrauth (
    ptr getelementptr inbounds ( ; <== raw unsigned pointer
      ptr,
      ptr @_ZTVN10__cxxabiv117__class_type_infoE,
      i64 2),
    i32 2,                       ; <== key
    i64 [[STDTYPEINFO_DISC]],    ; <== constant discr
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ptr @_ZTI10TestStruct),      ; <== address discr
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ptr @_ZTS10TestStruct
}
```

As far as I understand, the correct way of creating such structures which 
contain self-references, is to use `ConstantInitBuilder` and 
`getAddrOfCurrentPosition`. As far as I see from its source code, it handles 
self-references specially. With `ConstantInitBuilder`, we'll not end up with a 
vector of elements to be passed as struct initializer (`Fields` in our case) - 
instead, we'll need to call `finishAndSetAsInitializer` on the builder object.

As for `replaceInitializer` - sure, we can use it in existing code below, where 
we have `if (OldGV) { /* ... */ }`. But I'm not sure how it this newly proposed 
function can help us in context of this particular patch.

Do I miss smth? Can we somehow differently handle self-references and avoid 
using `ConstantInitBuilder`? Thanks in advance!



https://github.com/llvm/llvm-project/pull/102199
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to