Closed Bug 1354546 Opened 7 years ago Closed 7 years ago

Make LUL read CFI from the main executable on x86_64-Linux

Categories

(Core :: Gecko Profiler, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: jseward, Assigned: jseward)

References

Details

Attachments

(1 file, 1 obsolete file)

LUL doesn't read CFI from the main executable on x86_64-linux, and possibly
other Linux variants, because SharedLibraryInfo::GetInfoForSelf() doesn't
produce a name for the main executable object, even though it does notice the
mapping.

This causes noticeable unwind breakage because the main executable on Linux
contains various wrapper functions pertaining to memory allocation and locking,
such as

  moz_xmalloc, moz_xcalloc, moz_xrealloc
  mozilla::detail::MutexImpl::lock, mozilla::detail::MutexImpl::unlock

A proper fix is to tidy up shared-libraries-linux.cc and make it able to
identify the main executable properly.  As a short-term fix, we could simply
assume that any nameless object mapped at 0x400000 is the executable.  0x400000
is the "traditional" (x86_64-ELF mandated?) load address for executables on this
platform.

This will fail if the executable is position independent, but at least for
Fedora 25, Ubuntu 16.10 and probably for Debian, that's not the case by default.

This will also fail if (by some amazing chance) some other object with no name
gets mapped to 0x400000, since it will then be mis-identified as the executable.
This doesn't seem very likely, though.
Depends on: 1355052
Summary: Make LUL read CFI from the main executable on x86_64-Linux -- temporary fix → Make LUL read CFI from the main executable on x86_64-Linux
LUL doesn't read CFI from the main executable on x86_64-linux, and possibly
other Linux variants, because SharedLibraryInfo::GetInfoForSelf() doesn't
produce a name for the main executable object, even though it does notice the
mapping.

This causes noticeable unwind breakage because the main executable on Linux
contains various wrapper functions pertaining to memory allocation and locking,
such as

  moz_xmalloc, moz_xcalloc, moz_xrealloc
  mozilla::detail::MutexImpl::lock, mozilla::detail::MutexImpl::unlock

and is generally observable on x86_64-Linux as unwinding failures out of
functions with addresses around 0x40xxxx, since that's the traditional load
address for the main executable.

This patch modifies the Linux implementation of GetInfoForSelf() so as to
harvest the main executable's name from /proc/self/maps.  This is then added
into the information acquired from dl_iterate_phdr.  As a result
GetInfoForSelf() does correctly report the executable name, so LUL reads Dwarf
unwind info from it, and the abovementioned unwinding failures disappear.
Attachment #8856837 - Flags: review?(n.nethercote)
Assignee: nobody → jseward
Status: NEW → ASSIGNED
Attachment #8855801 - Attachment is obsolete: true
Comment on attachment 8856837 [details] [diff] [review]
Make LUL read CFI from the main executable on x86_64-Linux

Review of attachment 8856837 [details] [diff] [review]:
-----------------------------------------------------------------

::: tools/profiler/core/shared-libraries-linux.cc
@@ +26,5 @@
>  
>  // There are three different configuration cases:
>  //
>  // (1) GP_OS_linux
> +//       Use dl_iterate_phdr for almost everything and /proc/self/maps to

/proc/self/exe as well?

@@ +143,5 @@
> +  // address of its executable section (exeExeAddr) in the running image.
> +  char exeName[PATH_MAX];
> +  memset(exeName, 0, sizeof(exeName));
> +
> +  ssize_t exeNameLen = readlink("/proc/self/exe", exeName, sizeof(exeName)-1);

Nit: spaces around '-'.

@@ +260,5 @@
> +    SharedLibrary& lib = info.GetMutableEntry(i);
> +    if (lib.GetStart() == exeExeAddr && lib.GetNativeDebugPath() == "") {
> +      nsAutoString exeNameStr;
> +      mozilla::Unused
> +        << NS_WARN_IF(NS_FAILED(NS_CopyNativeToUnicode(

'<<' on preceding line.
Attachment #8856837 - Flags: review?(n.nethercote) → review+
Pushed by jseward@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/fef30348e68c
Make LUL read CFI from the main executable on x86_64-Linux.  r=n.nethercote.
https://hg.mozilla.org/mozilla-central/rev/fef30348e68c
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
Blocks: 1358360
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: