New user self-registration is disabled due to spam. For an account please email bugs-admin@lists.llvm.org with your e-mail address and full name.

Bug 9254 - clang can't build iptables in Linux kernel: error: fields must have a constant size: 'variable length array in structure' extension will never be supported
Summary: clang can't build iptables in Linux kernel: error: fields must have a constan...
Status: RESOLVED WONTFIX
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks: 4068
  Show dependency tree
 
Reported: 2011-02-19 04:31 PST by Török Edwin
Modified: 2019-01-30 08:47 PST (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Török Edwin 2011-02-19 04:31:40 PST
clang doesn't support this, and says it won't:
crypto/hmac.c:57:8: error: fields must have a constant size: 'variable length array in structure' extension will never be supported
                char ctx[crypto_shash_descsize(hash)];


That part of kernel code should probably be rewritten to not use this, but more and more kernel code seems to turn up that uses this feature of gcc.
It used to be only the crypto API, now it is iptables too.

Meanwhile I opened this bug to document how to turn off the problematic parts of the kernel, and its dependencies.
You need to turn off these:
CONFIG_INET_AH
CONFIG_INET_ESP
CONFIG_INET6_AH
CONFIG_INET6_ESP
CONFIG_NETFILTER
CONFIG_LIBCRC32C

The iptables is a problem though, without it we can't really say that "clang builds a Linux kernel".
How hard would it be to implement this specific case in clang?
And how hard would it be to patch the kernel to not use this feature?
Comment 1 Eli Friedman 2011-02-19 15:53:14 PST
Implementing this would be a crapload of verification work to make sure all the places that handle types handle structs with non-constant size, for handling a few rare constructs like this.

Working around this in the kernel would be easy: just replace the struct declaration with some other form of allocation (alloca, kmalloc, etc.).
Comment 2 Chris Lattner 2011-02-19 17:07:44 PST
I agree.  This an nested functions are two things we really really don't want to implement.
Comment 3 David Sterba 2011-02-21 04:45:36 PST
I have the crypto/hmac an iptables fixes ready and will push them upstream. Hmac should use explicit kmalloc and the hacky iptables macro in fact uses the VLA feature just to compute offset of some struct member which can be simply done by hand. There should be some documentation following why VLA feature should not be used at all, not only because clang does/will not support it, but because it may cause silent memory corruption.
Comment 4 Luke 2019-01-30 08:47:35 PST
Linux 4.20 kernel is now effectively VLA-free. 

https://patchwork.kernel.org/patch/10658685/