[llvm-dev] Using '__attribute__((section("name")))' for inline assembly injection
Martin J. O'Riordan via llvm-dev
llvm-dev at lists.llvm.org
Thu Oct 6 02:23:43 PDT 2016
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 at lists.llvm.org] On Behalf Of mats petersson via llvm-dev
Sent: 05 October 2016 21:48
To: Joerg Sonnenberger <joerg at bec.de>; llvm-dev <llvm-dev at lists.llvm.org>
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 at lists.llvm.org <mailto:llvm-dev at 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 at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161006/3012c260/attachment.html>
More information about the llvm-dev
mailing list