What does code pattern like .size X,.-X do?
Asked Answered
C

1

8

My question is about some popular but not well documented code I have found in ARM CORTEX M startup files like this STM32.

The 'pattern' is:

.size X,.-X

,where X is a symbol or label.

I have found this answer and understand how .size directive and dot special symbol work, but still complete line seems to do nothing to me. The result of the operation .-X isn't stored anywhere.

Could anybody explain what the line does?

Coldiron answered 15/10, 2018 at 13:40 Comment(5)
The result is stored in the metadata automatically by the .size directive.Pettifogger
The size calculation works exactly like $ - X in NASM: How does $ work in NASM, exactly?. But the .size directive emits ELF metadata with the function size, which is useful for shared libraries.Sprinkle
Thank you for answers! What will happen if I do not put this code after the function? Will it have negative impact on optimization only or my code won't work as expected?Coldiron
The effect of leaving it out is stuff like ARM Assembly Functions Appear With Size 0 in Symtab. I'm not sure if there are implications for correctness of static or dynamic linking. But it's just metadata, so if it works at all, there aren't any performance implications.Sprinkle
If you miss it out it might affect how well the debugging of the assembler works for the reasons in the comment above.Craquelure
G
7

That is placed at the end of function X, and the size of the function is the difference between the end of the function and the beginning. . is the current location so it's saying .size x is the difference between here and the label x.

Gypsophila answered 15/10, 2018 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.