[PATCH] D104420: thread_local support for AIX

Hubert Tong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 12 15:51:15 PDT 2021


hubert.reinterpretcast added inline comments.


================
Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:3003-3010
+    } else if (CGM.getTriple().isOSAIX())
+      // On AIX, all thread_local vars will have init routines regardless of
+      // whether they are const-initialized or not.  Since the routine is
+      // guaranteed to exist, we can unconditionally call it without testing
+      // for its existance.  This avoids potentially unresolved weak symbols
+      // which the AIX linker isn't happy with.
+      Builder.CreateCall(InitFnTy, Init);
----------------
Minor nit: The coding guidelines have been updated for some time to discourage mixed bracing on if/else chains (see example
```
// Use braces for the `if` block to keep it uniform with the else block.
```
).


================
Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:4790
+    llvm::Value *Arg2 = llvm::ConstantExpr::getBitCast(
+        cast<llvm::Constant>(dtor.getCallee()), FpTy);
+    CGF.EmitNounwindRuntimeCall(AtExit, {Arg1, Arg2});
----------------
hubert.reinterpretcast wrote:
> The function registered needs to be something more like what `createAtExitStub` stub creates. Otherwise, the destructor will not be able to reference `*this` correctly.
> 
> As it is, the registered function is currently just the destructor itself:
> ```
> $ clang++ -target powerpc64-ibm-aix -emit-llvm -S -o - -xc++ -<<<$'struct A { ~A(); }; thread_local A a;' | grep -C2 __pt_atexit_np
> define internal void @__cxx_global_var_init() #0 {
> entry:
>   %0 = call i32 (i32, i32 (i32, ...)*, ...) @__pt_atexit_np(i32 0, i32 (i32, ...)* bitcast (void (%struct.A*)* @_ZN1AD1Ev to i32 (i32, ...)*)) #3
>   ret void
> }
> --
> declare void @_ZN1AD1Ev(%struct.A* nonnull align 1 dereferenceable(1)) unnamed_addr #1
> 
> declare i32 @__pt_atexit_np(i32, i32 (i32, ...)*, ...)
> 
> ; Function Attrs: noinline
> Return:  0x00:0   Mon Jul 12 15:24:15 2021 EDT
> ```
Just noting that the callback function registered by the IBM XL compiler does not make an effort to return 0 (but the documentation says the handler "must" return 0: https://www.ibm.com/docs/en/aix/7.2?topic=p-pthread-atexit-np-subroutine).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104420/new/

https://reviews.llvm.org/D104420



More information about the cfe-commits mailing list