diff --git a/tests/mtouch/MTouch.cs b/tests/mtouch/MTouch.cs index 7d92b853e69b..f82d0156e3b8 100644 --- a/tests/mtouch/MTouch.cs +++ b/tests/mtouch/MTouch.cs @@ -33,6 +33,59 @@ public enum Profile { iOS, tvOS, watchOS } [TestFixture] public class MTouch { + [Test] + //[TestCase (Profile.iOS)] // tested as part of the watchOS case below, since that builds both for iOS and watchOS. + [TestCase (Profile.tvOS)] + [TestCase (Profile.watchOS)] + public void Profiling (Profile profile) + { + using (var mtouch = new MTouchTool ()) { + var tmpdir = mtouch.CreateTemporaryDirectory (); + MTouchTool ext = null; + if (profile == Profile.watchOS) { + mtouch.Profile = Profile.iOS; + + ext = new MTouchTool (); + ext.Profile = profile; + ext.Profiling = true; + ext.SymbolList = Path.Combine (tmpdir, "extsymbollist.txt"); + ext.CreateTemporaryWatchKitExtension (); + ext.CreateTemporaryDirectory (); + mtouch.AppExtensions.Add (ext); + ext.AssertExecute (MTouchAction.BuildDev, "ext build"); + } else { + mtouch.Profile = profile; + } + mtouch.CreateTemporaryApp (); + mtouch.CreateTemporaryCacheDirectory (); + + mtouch.DSym = false; // faster test + mtouch.MSym = false; // faster test + mtouch.NoStrip = true; // faster test + + mtouch.Profiling = true; + mtouch.SymbolList = Path.Combine (tmpdir, "symbollist.txt"); + mtouch.AssertExecute (MTouchAction.BuildDev, "build"); + + var profiler_symbol = "_mono_profiler_startup_log"; + + var symbols = File.ReadAllLines (mtouch.SymbolList); + Assert.That (symbols, Contains.Item (profiler_symbol), profiler_symbol); + + symbols = ExecutionHelper.Execute ("nm", StringUtils.Quote (mtouch.NativeExecutablePath), hide_output: true).Split ('\n'); + Assert.That (symbols, Has.Some.EndsWith (" T " + profiler_symbol), $"{profiler_symbol} nm"); + + if (ext != null) { + symbols = File.ReadAllLines (ext.SymbolList); + Assert.That (symbols, Contains.Item (profiler_symbol), $"{profiler_symbol} - extension"); + + symbols = ExecutionHelper.Execute ("nm", StringUtils.Quote (ext.NativeExecutablePath), hide_output: true).Split ('\n'); + Assert.That (symbols, Has.Some.EndsWith (" T " + profiler_symbol), $"{profiler_symbol} extension nm"); + + } + } + } + [Test] public void ExceptionMarshaling () { diff --git a/tests/mtouch/MTouchTool.cs b/tests/mtouch/MTouchTool.cs index 5c405778a941..765a8771f76a 100644 --- a/tests/mtouch/MTouchTool.cs +++ b/tests/mtouch/MTouchTool.cs @@ -120,6 +120,8 @@ class MTouchTool : Tool, IDisposable public string AotOtherArguments; public string [] LinkSkip; public string [] XmlDefinitions; + public bool? Profiling; + public string SymbolList; #pragma warning restore 649 @@ -307,6 +309,12 @@ string BuildArguments (MTouchAction action) } } + if (Profiling.HasValue) + sb.Append (" --profiling:").Append (Profiling.Value ? "true" : "false"); + + if (!string.IsNullOrEmpty (SymbolList)) + sb.Append (" --symbollist=").Append (StringUtils.Quote (SymbolList)); + if (MSym.HasValue) sb.Append (" --msym:").Append (MSym.Value ? "true" : "false"); diff --git a/tools/common/CompilerFlags.cs b/tools/common/CompilerFlags.cs index df0434154727..a5af6f7e6b31 100644 --- a/tools/common/CompilerFlags.cs +++ b/tools/common/CompilerFlags.cs @@ -45,14 +45,6 @@ public HashSet AllLibraries { } } - public void ReferenceSymbol (string symbol) - { - if (UnresolvedSymbols == null) - UnresolvedSymbols = new HashSet (); - - UnresolvedSymbols.Add (symbol); - } - public void ReferenceSymbols (IEnumerable symbols) { if (UnresolvedSymbols == null) diff --git a/tools/common/Target.cs b/tools/common/Target.cs index d998f0b4109a..fb56de22e51c 100644 --- a/tools/common/Target.cs +++ b/tools/common/Target.cs @@ -238,6 +238,11 @@ public void CollectAllSymbols () dynamic_symbols.AddFunction ("xamarin_dyn_objc_msgSendSuper_stret"); } +#if MONOTOUCH + if (App.EnableProfiling && App.LibProfilerLinkMode == AssemblyBuildTarget.StaticObject) + dynamic_symbols.AddFunction ("mono_profiler_startup_log"); +#endif + dynamic_symbols.Save (cache_location); } diff --git a/tools/mtouch/Target.cs b/tools/mtouch/Target.cs index 51e534a16faa..ad8a7e533ece 100644 --- a/tools/mtouch/Target.cs +++ b/tools/mtouch/Target.cs @@ -1396,8 +1396,6 @@ public void NativeLink (BuildTasks build_tasks) case AssemblyBuildTarget.StaticObject: libprofiler = Path.Combine (libdir, "libmono-profiler-log.a"); linker_flags.AddLinkWith (libprofiler); - if (!App.EnableBitCode) - linker_flags.ReferenceSymbol ("mono_profiler_startup_log"); break; case AssemblyBuildTarget.Framework: // We don't ship the profiler as a framework, so this should be impossible. default: