minipli / linux-unofficial_grsec

Unofficial forward ports of the last publicly available grsecurity patch
Other
150 stars 30 forks source link

size_overflow_plugin fails to build with GCC6 and musl-libc #9

Closed parazyd closed 7 years ago

parazyd commented 7 years ago

Since GCC6 the size_overflow_plugin fails to build due to the prototype in musl's libgen.h being different than libiberty. The error message is as such:

tatooine /usr/src/linux  # make
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  HOSTCXX -fPIC scripts/gcc-plugins/size_overflow_plugin/size_overflow_ipa.o
In file included from scripts/gcc-plugins/size_overflow_plugin/size_overflow_ipa.c:21:0:
/usr/include/libgen.h:9:7: error: conflicting declaration of C function 'char* basename(char*)'
 char *basename(char *);
       ^~~~~~~~
In file included from /usr/lib/gcc/x86_64-gentoo-linux-musl/6.4.0/plugin/include/system.h:685:0,
                 from /usr/lib/gcc/x86_64-gentoo-linux-musl/6.4.0/plugin/include/gcc-plugin.h:28,
                 from scripts/gcc-plugins/gcc-common.h:6,
                 from scripts/gcc-plugins/size_overflow_plugin/size_overflow.h:29,
                 from scripts/gcc-plugins/size_overflow_plugin/size_overflow_ipa.c:20:
/usr/lib/gcc/x86_64-gentoo-linux-musl/6.4.0/plugin/include/libiberty.h:112:14: note: previous declaration 'char* basename(const char*)'
 extern char *basename (const char *) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_NONNULL(1);
              ^~~~~~~~
make[2]: *** [scripts/Makefile.host:158: scripts/gcc-plugins/size_overflow_plugin/size_overflow_ipa.o] Error 1
make[1]: *** [scripts/Makefile.build:544: scripts/gcc-plugins/size_overflow_plugin] Error 2
make: *** [scripts/Makefile.gcc-plugins:129: gcc-plugins] Error 2

To fix it, we can apply the following patch:

--- scripts/gcc-plugins/size_overflow_plugin/size_overflow_ipa.c.orig   2017-09-09 21:47:58.442437114 +0200
+++ scripts/gcc-plugins/size_overflow_plugin/size_overflow_ipa.c    2017-09-09 21:47:11.851434184 +0200
@@ -18,7 +18,7 @@
  */

 #include "size_overflow.h"
-#include <libgen.h>
+extern const char *lbasename (const char *);

 static void walk_use_def_next_functions(struct walk_use_def_data *use_def_data, tree lhs);

@@ -52,14 +52,15 @@ static bool compare_next_interesting_fun
 static const char* get_vardecl_context(const_tree decl)
 {
    expanded_location xloc;
-   char *buf, *path;
+   char *buf;
+   const char *path;
    const char *bname;
    int len;

    xloc = expand_location(DECL_SOURCE_LOCATION(decl));
    gcc_assert(xloc.file);
    path = xstrdup(xloc.file);
-   bname = basename(path);
+   bname = lbasename(path);

    len = asprintf(&buf, "vardecl_%s", bname);
    gcc_assert(len > 0);

Keep in mind I haven't done a test on glibc or versions of GCC older than 6. Would you consider applying this patch for future releases?

minipli commented 7 years ago

Thanks for the report and the patch. Apparently musl, glibc and libiberty all have a different understanding on how to declare basename(3). Your patch works around that. However, it does so rather hacky, so I will fix it slightly differently. ;)

minipli commented 7 years ago

Fixed with commit 99af2b65dbe4 ("pax, size_overflow: fix build with musl headers").