Skip to content

[Bug]: Effect of ABSL_FLAGS_STRIP_NAMES on mobile platforms is poorly documented #1875

Open
@jiawen

Description

@jiawen

Describe the issue

I am porting command line C++ code to use on iOS. Setting aside the issue of actually passing command line arguments to an iOS app (it is possible and fully supported), calling absl::ParseCommandLine(argc, argv) on stack variables seems to fail mysteriously. Even within the same translation unit, ABSL_FLAG definitions are ignored and not present in the .o.

I thought this was an issue with my toolchain configuration (linker stripping, etc). But it turns out, it is due to ABSL_FLAGS_STRIP_NAMES being set to 0 on "mobile" targets, where "mobile" is defined to be Android, iPhone, and "embedded Apple devices".

While explicitly setting ABSL_FLAGS_STRIP_NAMES=0 fixes the issue, the name ABSL_FLAGS_STRIP_NAMES is confusing as its effect is to disable flag registration altogether: ABSL_FLAG_IMPL is defined to call absl::flags_internal::FlagRegistrar<T, /*do_register=*/false> or absl::flags_internal::FlagRegistrar<T, /*do_register=*/true>.

I am not advocating that we change the name - that's extremely disruptive.

But maybe we should better document it somewhere as this behavior is surprising (albeit rare - I don't know how many Abseil users actually want to pass flags to iOS apps. My team for one would like to do this as it conveniently lets us pass things like --stderrthreshold 0.

Steps to reproduce the problem

Write a C++ library that looks like:

ABSL_FLAG(int, value1, 0, "value1");
ABSL_FLAG(double, value2, 0.0, "value2");

void parse() {
  int argc = 4;
  char* argv[4] = {
      "app",
      "--value1=6",
      "--value2",
      "7.6",
  };
  absl::ParseCommandLine(argc, argv);
}

and call parse() from the iOS app. It will mysteriously complain:

ERROR: Unknown command line flag 'value1'
ERROR: Unknown command line flag 'value2'

Building with ABSL_FLAGS_STRIP_NAMES=0 fixes the issue.

What version of Abseil are you using?

20240722.0

What operating system and version are you using?

iOS 18.0

What compiler and version are you using?

Xcode 16.0

$ clang -v
Apple clang version 16.0.0 (clang-1600.0.26.3)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Applications/Xcode_16.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

What build system are you using?

bazel 7.1.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions