[clang] [llvm] [clang, SystemZ] Pass HasDef flag to getMinGlobalAlign(). (PR #73511)

Jonas Paulsson via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 29 02:53:00 PST 2023


================
@@ -1687,7 +1687,8 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const {
       if (VD->hasGlobalStorage() && !ForAlignof) {
         uint64_t TypeSize =
             !BaseT->isIncompleteType() ? getTypeSize(T.getTypePtr()) : 0;
-        Align = std::max(Align, getTargetInfo().getMinGlobalAlign(TypeSize));
+        Align = std::max(Align, getTargetInfo().getMinGlobalAlign(
+                                    TypeSize, VD->hasDefinition()));
----------------
JonPsson1 wrote:

I can't see that this is working with weak symbols with (recent) GCC:

```
test2.c:
 #include <stdio.h> 

char __attribute__((weak)) c0_weak = 0;
char __attribute__((weak)) c1_weak = 0;
 
int main() { 
  printf("%d\n", c0_weak + c1_weak); 
}

test2_1.c:
char __attribute__((aligned(1))) c0_weak = 1;
char __attribute__((aligned(1))) c1_weak = 1;
```

```
gcc ./test2.c ./test2_1.c -O3 -munaligned-symbols -S -c
main:
.LFB11:
	.cfi_startproc
	larl	%r2,c0_weak
	larl	%r1,c1_weak
        ...
```

```
~/gcc-latest/bin/gcc ./test2.c ./test2_1.c -O3 -munaligned-symbols
/usr/bin/ld: /tmp/ccj8BnuO.o(.text.startup+0x2): misaligned symbol `c0_weak' (0x1004021) for relocation R_390_PC32DBL
collect2: error: ld returned 1 exit status
```

https://github.com/llvm/llvm-project/pull/73511


More information about the cfe-commits mailing list