(original) (raw)
My own preference is for a warning, that way the issue is visible and the programmer can choose to ignore it, disable it or make it an error as preferred.
I tried it with embedded NUL characters, and this turned out not to be a good idea. The example:
\_\_attribute\_\_((section("grok\\nfubar\\0poisoned\\tsnafu")))
int foo() { return 42; }
with clang v3.8.0 for X86 ‘clang -Wall -S section.c’ I get the following output and no warnings:
.text
.def foo;
.scl 2;
.type 32;
.endef
.section grok
fubar,"xr"
.globl foo
.align 16, 0x90
foo: # @foo
.Ltmp0:
.seh\_proc foo
# BB#0: # %entry
.Ltmp1:
.seh\_endprologue
movl $42, %eax
retq
.seh\_handlerdata
.section grok
fubar,"xr"
.Ltmp2:
.seh\_endproc
Since we do not have an integrated assembler, we have to go through the emit-assembly and separate invocation of the assembler, and such constructs fail at the next level.
I don’t know, perhaps when the compiler is writing object code directly it can somehow make the whole string meaningful as a section name, though I’m not sure how I could write an LD script for such sections.
I don’t advocate the programmer doing this kind of trick to force assembly code into the emitted assembly code; it seems very dangerous. The ‘\_\_attribute\_\_((naked))’ was changed a few versions ago so that a function defined with this attribute could not contain C source code. I haven’t experimented with it since then.
Thanks,
MartinO
From: llvm-dev \[mailto:llvm-dev-bounces@lists.llvm.org\] On Behalf Of mats petersson via llvm-dev
Sent: 05 October 2016 21:48
To: Joerg Sonnenberger ; llvm-dev
Subject: Re: \[llvm-dev\] Using '\_\_attribute\_\_((section("name")))' for inline assembly injection
On 5 October 2016 at 21:39, Joerg Sonnenberger via llvm-dev <llvm-dev@lists.llvm.org> wrote:
On Wed, Oct 05, 2016 at 12:44:29PM -0500, Hal Finkel via llvm-dev wrote:
> Would it be useful for Clang to warn about section names with unusual characters?
I don't think it is common enough and you can always check the output
easily with readelf/objdump.
I would think that it's very uncommon, however, it is also terribly difficult to detect, and I'd argue that it's unlikely that someone actually wishes to have newlines or other "non-printable"/"control" characters in the section name. And if it's a warning that is enabled by default but possible to turn off with "-wno-weird-sectionname", I'd say it would be little harm - and not a huge maintenance burden.
Knowing to check that the section names contain weirdness or otherwise debug "why the heck doesn't this code work in Clang, when it compiels without warning, and is fine when compiled in gcc or whatever" is really not at all easy.
I do realise that "every warning and such is a maintenance burden", but although I have not encountered this problem, I'd definitely prefer a warning than having to figure what went wrong...
--
Mats
Joerg\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
LLVM Developers mailing list
llvm-dev@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev