Skip to content

Commit

Permalink
[mtouch] Put 'mono_profiler_startup_log' in the symbol list. Fixes #5…
Browse files Browse the repository at this point in the history
…8778. (#2501)

We need the 'mono_profiler_startup_log' symbol when profiling is enabled, so
make sure to add the symbol to the correct list of symbols we need.

Previously we were passing `-u _mono_profiler_startup_log` to clang directly,
which is fine, but not complete, since it does not write the symbol to the
symbollist file (--symbollist=file), which means it wouldn't be preserved when
the MSBuild tasks strip the executable.

https://bugzilla.xamarin.com/show_bug.cgi?id=58778
  • Loading branch information
rolfbjarne authored Aug 18, 2017
1 parent 4e0c545 commit f60801b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 10 deletions.
53 changes: 53 additions & 0 deletions tests/mtouch/MTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
Expand Down
8 changes: 8 additions & 0 deletions tests/mtouch/MTouchTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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");

Expand Down
8 changes: 0 additions & 8 deletions tools/common/CompilerFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ public HashSet<string> AllLibraries {
}
}

public void ReferenceSymbol (string symbol)
{
if (UnresolvedSymbols == null)
UnresolvedSymbols = new HashSet<string> ();

UnresolvedSymbols.Add (symbol);
}

public void ReferenceSymbols (IEnumerable<Symbol> symbols)
{
if (UnresolvedSymbols == null)
Expand Down
5 changes: 5 additions & 0 deletions tools/common/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 0 additions & 2 deletions tools/mtouch/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f60801b

Please sign in to comment.