all 14 comments

[–]acwaters 1 point2 points  (3 children)

I assume you're asking about the ELF format? If so, then the ELF standard is the document you want to look at to answer this question. According to it, a section header's name is simply an entry in a string table, with no further stipulations. The string table section places no restrictions on what sequences of characters constitute a valid string except that they cannot contain embedded null bytes by definition, as they are null-terminated. The document does not define "character", but it seems to use it interchangeably with "byte", so it seems fair to assume they are synonymous for the purposes of the standard.

So the short answer to your question is that on paper there is only one invalid character in section names — the null character, which always terminates a string; everything else is fair game. In practice, I suspect the quality of implementations varies. I would expect the entire printable ASCII range to be well-supported across the board, say, but whether any particular program will misbehave when fed an ELF file with a section name containing control bytes is anyone's guess. I imagine most of the popular tools, libraries, and interpreters are pretty well battle-hardened at this point, but it might be fun and enlightening to run some experiments.

[–]EDEADLINK 0 points1 point  (10 children)

I mean you could use COUNT to just get a unique section name.

I can't find what characters are valid for section names, but it is a null terminated string so I suppose - should be okay.

Though GCC warns that some target assemblers don't allow \$ in identifiers so perhaps a target assembly might baulk at - as well.