On Fri, 5 Jun 2015, Pinski, Andrew wrote:

> I am just going to say, I don't like this extension at all.  It allows for 
> abuse than it is good.

What abuses do you forsee? Could you elaborate please?

> Oh and why can't you use the C preprocessor to do this section 
> renaming? I know for a fact the kernel uses the preprocessor for 
> assembly code all over the place and I don't see why this would not be 
> so different.

I did try, obviously.

Take for example this construct:

#define __get_user_asm_byte(x, addr, err)                       \
        __asm__ __volatile__(                                   \
        "1:     ldrbt   %1,[%2],#0\n"                           \
        "2:\n"                                                  \
        "       .pushsection .text.fixup,\"ax\"\n"              \
        "       .align  2\n"                                    \
        "3:     mov     %0, %3\n"                               \
        "       mov     %1, #0\n"                               \
        "       b       2b\n"                                   \
        "       .popsection\n"                                  \
        "       .pushsection __ex_table,\"a\"\n"                \
        "       .align  3\n"                                    \
        "       .long   1b, 3b\n"                               \
        "       .popsection"                                    \
        : "+r" (err), "=&r" (x)                                 \
        : "r" (addr), "i" (-EFAULT)                             \
        : "cc")

Now this code can be used by functions placed either in the .text 
section, the .init.text section, or the .exit.text section.  If this is 
compiled into the kernel instead of being configured as a module, then 
we want to be able to discard at run time any .init.text content and 
avoid linking in the .exit.text sections altogether.  But if the 
.exit.text section is omitted, then you'll get a symbol reference error 
because both the .text.fixup and __ex_table sections hold references to 
some code in .exit.text.  The only way to solve this is to have a 
separate section for .exit.text induced fixup code and exception table 
entries so they can be discarded at the linker level along with the 
.exit.text section.

Now the section type could be passed as an argument to the 
__get_user_asm_byte() macro you might suggest.  But we can't always know 
the actual section in use.  For example there are many of those macros 
used within larger inline functions (or sometimes it is gcc who inlines 
stuff on its own).  Those functions are used either from .text, .init or 
.exit code at the moment. Attempting to pass the section information 
across many levels quickly becomes unwieldly and a maintenance 
nightmare. It works only when constant propagation is applied, and if 
for some reason gcc decides not to inline things then the section 
identifier is no longer a constant to the leaf function.

In the course of my work on kernel tinification, I'm also contempling 
the use of -ffunction-sections and -fdata-sections with gcc, in 
conjonction with ld's -gc-sections which would emplify this issue to all 
functions.  Here I tried to use __func__ and pass it to the the 
assembler, but __func__ acts like a string pointer and terefore can't be 
used to form an anciliary section name at the assembler level.  And even 
if it worked, once again function inlining makes it wrong because 
__func__ produces a string corresponding to the local function whereas 
the actual section name would refer to the outer function where the 
inlining occurred, and if the section corresponding to the inlined 
function is actually in another instance then the whole section may no 
longer be garbage-collected.

So... my conclusion is that, to solve those issues in the simplest and 
the most robust way, it should be implemented at the assembler level, 
hence the patch I'm now proposing.  If you do think about a better way 
to achieve the same thing please tell me -- I'll be highly interested.

Thanks


Nicolas
_______________________________________________
linaro-toolchain mailing list
linaro-toolchain@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/linaro-toolchain

Reply via email to