Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jiawen opened this issue Apr 16, 2025 · 0 comments

Comments

@jiawen
Copy link

jiawen commented Apr 16, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant