llvm-size uses "isText()" etc. which seem to indicate whether the section contains code-like things, not whether or not it will actually go in the text segment when in a fully linked executable.
The unit test added (elf-sizes.test) shows some types of sections that cause discrepencies versus the GNU size tool. llvm-size is not correctly reporting sizes of things mapping to text/data segments, at least for ELF files.
This fixes pr38723.
The parentheses outside of ! are redundant.
GNU size uses Berkeley format by default (static int berkeley_format = BSD_DEFAULT;)
I'd say it uses a weird counting https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=binutils/size.c;h=3c72e484752d0272a24ac628f497f89ecf36d547;hb=refs/heads/master#l459
459 if ((flags & SEC_CODE) != 0 || (flags & SEC_READONLY) != 0)
460 textsize += size;
461 else if ((flags & SEC_HAS_CONTENTS) != 0)
462 datasize += size;
463 else
464 bsssize += size;
Basically SHF_EXECINSTR sections (.text) + !SHF_WRITE sections (.rodata .eh_frame ...).
I feel the name inTextSegment is a bit misleading. How about isBerkeleyText?
inDataSegment may be renamed to isBerkeleyData.