<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69939>69939</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Constructor size is twice as large on Clang17.0.2 with MTE enabled
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
P1119r1m
</td>
</tr>
</table>
<pre>
To reproduce the problem 2 files should be created:
- main.c
```
typedef int (*ctor_t)(void);
#define __constructor__ \
__attribute__((__used__)) __attribute__((__section__(".ctors")))
#define DECLARE_CONSTRUCTOR(fn) \
static ctor_t ctor_##fn __constructor__ = fn
static int init_FIRST_func(void) { return 0; }
static int init_SECOND_func(void) { return 0; }
DECLARE_CONSTRUCTOR(init_FIRST_func);
DECLARE_CONSTRUCTOR(init_SECOND_func);
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
return 0;
}
```
- build.sh
```
#!/bin/bash
## CONFIG
# 16.0.6 (llvmorg-v16.0.6 tag) - THE PROBLEM COULD NOT BE REPRODUCED
CLANG_DIR=... !!! USE YOUR PATH !!! ...
# 17.0.0 (llvmorg-v17-init tag) - THE PROBLEM COULD NOT BE REPRODUCED
CLANG_DIR=... !!! USE YOUR PATH !!! ...
# 17.0.2 (llvmorg-17.0.2 tag) - THE PROBLEM COULD BE REPRODUCED
CLANG_DIR=... !!! USE YOUR PATH !!! ...
# 17.0.3 (llvmorg-17.0.3 tag) - THE PROBLEM COULD BE REPRODUCED
CLANG_DIR=... !!! USE YOUR PATH !!! ...
CC="${CLANG_DIR}/bin/clang"
LLD="${CLANG_DIR}/bin/ld.lld"
OBJDUMP="${CLANG_DIR}/bin/llvm-objdump"
CC_FLAGS="-march=armv8.3-a+memtag -fsanitize=memtag" # COMMENT THIS CODE TO "FIX" THE ISSUE!
## COMPILE
${CC} ${CC_FLAGS} -c main.c -o main.o
## LINK
${LLD} main.o -o ./main.syms
## ANALYZE <BEGIN>
echo -e "\n\n>>>>>>>> Show functions' addresses in compiled *.o file <<<<<<<<"
${OBJDUMP} -dS main.o | grep '<init_'
echo -e "\n\n>>>>>>>> Show Clang version <<<<<<<<"
${CC} --version
echo -e "\n\n>>>>>>>> Show contstructors' code in final binary <<<<<<<<"
${OBJDUMP} -dS -j ".ctors" main.syms
## ANALYZE <END>
```
The output for the "source build.sh" run command is following:
```
$ source build.sh
...
0000000000220230 <ctor_init_SECOND_func>:
220230: f4 01 21 00 .word 0x002101f4 <---- NOTE: 16 bytes (and this is a problem, IMHO)
220234: 00 00 00 00 .word 0x00000000
220238: 00 00 00 00 .word 0x00000000
22023c: 00 00 00 00 .word 0x00000000
```
In case of using "Clang17.0.0" from the "llvmorg-v17-init" tag:
```
0000000000220228 <ctor_init_SECOND_func>:
220228: f4 01 21 00 .word 0x002101f4 <---- NOTE: 8 bytes
22022c: 00 00 00 00 .word 0x00000000
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV99v4jgQ_mvMyyhRsCmBBx4gCS13FCp-SLf3EjmOA14lMbIdet2__uQk_GjLbnu7ujtkaGLPN_lmvonHpVqLXcn5CN1N0F3YoZXZSzV66na7Q9UtOolMX0YbCYoflEwrxsHsORyUTHJeAIZM5FyD3ssqTyHhwBSnhqeIjJEXIm_sQEFF6bLmDvW9dtS35uXAU56BKA0gPEB4zIxUsUF4iPDgKEVqr8ikBTe_mKQ8EyWHOGay1EZVNSgGAEB3QWNlb-KYGqNEUhkex7X7QRxXmqf2bojw8LaF5swIWbYT2LXeNcK4wdhxk00YBfPxKoqD5WK9WW2DzXKF8CAr7XPeMtOGGsGgCbb5gzBBmGTlu6gQCSErr5_Zom3SRClMPJ2t1ps4q0p2SRogfwKKm0qV4CEyAeSHt9HrKFguwk_Dm9_bwb5jc9HuB4BXBN6qbWnaAqqNDVC1YwgHwPZUAcJjqnbHpnBb0pccX4KpQeR7S8fL0lXALYdz1K_r9lTaSSXy1NX720ZW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