Skip to content

g++ fpermissive compilation error for strdupa on musl when buiding from source #15729

@xhebox

Description

@xhebox

Description of the bug:

g++ will report errors as follows:

In file included from src/main/tools/linux-sandbox-pid1.cc:34:
src/main/tools/linux-sandbox-pid1.cc: In function ‘int CreateTarget(const char*, bool)’:
src/main/tools/linux-sandbox-pid1.cc:149:28: error: invalid conversion from ‘void*’ to ‘char*’ [-fpermissive]
  149 |   if (CreateTarget(dirname(strdupa(path)), true) < 0) {
      |                            ^
      |                            |
      |                            void*
In file included from src/main/tools/linux-sandbox-pid1.cc:34:
/include/string.h:33:15: note:   initializing argument 1 of ‘char* strcpy(char*, const char*)’
   33 | char *strcpy (char *__restrict, const char *__restrict);
      |               ^~~~~~~~~~~~~~~~
In file included from src/main/tools/linux-sandbox-pid1.cc:67:
src/main/tools/linux-sandbox-pid1.cc:150:36: error: invalid conversion from ‘void*’ to ‘char*’ [-fpermissive]
  150 |     DIE("CreateTarget %s", dirname(strdupa(path)));
      |                                    ^
      |                                    |
      |                                    void*
./src/main/tools/logging.h:36:51: note: in definition of macro ‘DIE’
   36 |     fprintf(stderr, __FILE__ ":" S__LINE__ ": \"" __VA_ARGS__); \
      |                                                   ^~~~~~~~~~~
In file included from src/main/tools/linux-sandbox-pid1.cc:34:
/include/string.h:33:15: note:   initializing argument 1 of ‘char* strcpy(char*, const char*)’
   33 | char *strcpy (char *__restrict, const char *__restrict);

I've sent patches to musl, ref this. Despite whether musl will accept the patch, I agreed with the author of musl that using strdupa is probably not a good idea. And we have other replacement.

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Build bazel 5.2.0 on musl by:

curl -O -L https://github.com/bazelbuild/bazel/releases/download/5.2.0/bazel-5.2.0-dist.zip
7z x bazel-5.2.0.zip
EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk" ./compile.sh

You could try this on an docker alpine linux image.

Which operating system are you running Bazel on?

linux with musl libc

What is the output of bazel info release?

No response

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3We're not considering working on this, but happy to review a PR. (No assignee)help wantedSomeone outside the Bazel team could own thisteam-OSSIssues for the Bazel OSS team: installation, release processBazel packaging, websitetype: support / not a bug (process)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions