[cfe-dev] Silly: why I don't see effect of -fstack-size-section?

Fangrui Song via cfe-dev cfe-dev at lists.llvm.org
Sat Jul 18 14:21:02 PDT 2020


On 2020-07-17, Renat Idrisov via cfe-dev wrote:
>Hi All,
>I have the following piece of code:
>
>```
>#include <stdio.h>
>
>int abc(void) {
>  char a[4];
>  a[0] = 0;
>  printf("%c", a[0]);
>  return 0;
>}
>```
>
>I do:
>$ /usr/local/Cellar/llvm/10.0.0_3/bin/clang stack.c -c -fstack-size-section
>$ ls -la stack.o
>-rw-r--r--  1 renat  staff  760 Jul 17 15:31 stack.o
>$ /usr/local/Cellar/llvm/10.0.0_3/bin/clang stack.c -c
>-fno-stack-size-section
>$ ls -la stack.o
>-rw-r--r--  1 renat  staff  760 Jul 17 15:32 stack.o
>
>also if I try to find the section, I don't see it (with
>-fstack-size-section)
>$ objdump -s stack.o
>
>stack.o: file format Mach-O 64-bit x86-64
>
>Contents of section __text:
> 0000 554889e5 4883ec10 c645fc00 0fbe75fc  UH..H....E....u.
> 0010 488d3d14 000000b0 00e80000 000031c9  H.=...........1.
> 0020 8945f889 c84883c4 105dc3             .E...H...].
>Contents of section __cstring:
> 002b 256300                               %c.
>Contents of section __compact_unwind:
> 0030 00000000 00000000 2b000000 00000001  ........+.......
> 0040 00000000 00000000 00000000 00000000  ................
>Contents of section __eh_frame:
> 0050 14000000 00000000 017a5200 01781001  .........zR..x..
> 0060 100c0708 90010000 24000000 1c000000  ........$.......
> 0070 90ffffff ffffffff 2b000000 00000000  ........+.......
> 0080 00410e10 8602430d 06000000 00000000  .A....C.........
>
>What am I missing?
>
>Thank you!

-fstack-size-sections is only available for ELF (not for COFF/Mach-O/wasm/etc).

There is interesting design issues related to dead stripping/COMDAT/cost
of metadata sections. This is currently fixed in ELF (due to the use of SHF_LINK_ORDER,
GNU as and ld from GNU binutils 2.35 onwards work). Similar
considerations need to be taken if someone wants to support other binary formats.


More information about the cfe-dev mailing list