MobileNativeFoundation / MobileNativeFoundation/rules_xcodeproj

Bug: Address Sanitizer Does not work with Physical Device

Open
#2,844 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Swift
Stars
626
Forks
124
PR merge metrics
No merged PRs in 30d

Description

Description

Using Address Sanitizer in physical device cause error

dyld[17268]: Library not loaded: @rpath/libclang_rt.asan_ios_dynamic.dylib
  Referenced from: <C7946C17-CFDB-39C7-8EDC-C760B1E67372> /private/var/containers/Bundle/Application/A614A60F-3AC2-4585-9E18-F89AC83FF032/AddressSanitizerApp.app/AddressSanitizerApp
  Reason: tried: '/usr/lib/system/introspection/libclang_rt.asan_ios_dynamic.dylib' (no such file, not in dyld cache), '/usr/lib/swift/libclang_rt.asan_ios_dynamic.dylib' (no such file, not in dyld cache),
Screenshot 2024-01-03 at 18 30 18

Extra info:

https://github.com/flutter/flutter/issues/108469

It looks like the ios asan dylib is no longer vended with the clang toolchain that the engine consumes, but Xcode has the dylib, so we could try to use that one.

Reproduction steps
  1. Add target_environments device in example/sanitizers/xcodeproj_targets.bzl
load("@rules_xcodeproj//xcodeproj:defs.bzl", "xcode_schemes", "top_level_target")

SCHEME_AUTOGENERATION_MODE = "none"

_ADDRESS_SANITIZER_TARGET = "//AddressSanitizerApp"
_THREAD_SANITIZER_TARGET = "//ThreadSanitizerApp"
_UNDEFINED_BEHAVIOR_SANITIZER_TARGET = "//UndefinedBehaviorSanitizerApp"

XCODEPROJ_TARGETS = [
    top_level_target(_ADDRESS_SANITIZER_TARGET, target_environments = ["simulator", "device"]),
    _THREAD_SANITIZER_TARGET,
    _UNDEFINED_BEHAVIOR_SANITIZER_TARGET,
]
  1. Setup Provisioning profile in the example/sanitizers/AddressSanitizerApp/
load("@build_bazel_rules_apple//apple:apple.bzl", "local_provisioning_profile")

local_provisioning_profile(
    name = "app_debug_profile",
    profile_name = "iOS Team Provisioning Profile: xyz",
    team_id = "XYZ",
)

ios_application(
    provisioning_profile = ":app_debug_profile",
)
  1. Generate the project bazel run //:xcodeproj
  2. Run the AddressSanitizer in the real device.
Expected behavior

Work the same as the simulator.

rules_xcodeproj version

1.14.2

Xcode version

15.1

Bazel version

7.0.0

rules_apple version

3.1.1

rules_swift version

1.13.0

Additional information

I check the rules_apple and rules_swift version from the examples/rules_ios/MODULE.bazel

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with example/sanitizers/xcodeproj_targets.bzl and the AddressSanitizerApp setup described in the reproduction steps. Compare the generated project and sanitizer configuration for simulator and device targets, then verify the AddressSanitizer app launches on a physical device with the listed provisioning setup. Done means device behavior matches the simulator without the missing dylib error.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, swift
Domain
build-system, devtools, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.