)]}'
{
  "commit": "a8651ef51822f91ec86d0d5caffbf2e50b174c23",
  "tree": "ce94d7b8c5fb0635c1ae7fd758c5e8d2113b3c16",
  "parents": [
    "0696ccbdb57b0a0d1ed34ed83b963a875ceffd1e"
  ],
  "author": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Wed Jun 12 13:10:53 2024 -0400"
  },
  "committer": {
    "name": "Andrew Burgess",
    "email": "aburgess@redhat.com",
    "time": "Fri Jun 14 14:47:38 2024 +0100"
  },
  "message": "gdb/aarch64: prevent crash from in process agent\n\nSince this commit:\n\n  commit 0ee6b1c511c0e2a6793568692d2e5418cd6bc10d\n  Date:   Wed May 18 13:32:04 2022 -0700\n\n      Use aarch64_features to describe register features in target descriptions.\n\nThere has been an issue with how aarch64 target descriptions are\ncached within gdbserver, and specifically, how this caching impacts\nthe in process agent (IPA).\n\nThe function initialize_tracepoint_ftlib (gdbserver/tracepoint.cc) is\npart of the IPA, this function is a constructor function, i.e. is\ncalled as part of the global initialisation process.  We can\u0027t\nguarantee the ordering of when this function is called vs when other\nglobal state is initialised.\n\nNow initialize_tracepoint_ftlib calls initialize_tracepoint, which\ncalls initialize_low_tracepoint, which for aarch64 calls\naarch64_linux_read_description.\n\nThe aarch64_linux_read_description function lives in\nlinux-aarch64-tdesc.cc and after the above commit, depends on a\nstd::unordered_map having been initialized.\n\nPrior to the above commit aarch64_linux_read_description used a global\nC style array, which obviously requires no runtime initialization.\n\nThe consequence of the above is that any inferior linked with the IPA\n(for aarch64) will experience undefined behaviour (access to an\nuninitialized std::unordered_map) during startup, which for me\nmanifests as a segfault.\n\nI propose fixing this by moving the std::unordered_map into the\nfunction body, but leaving it static.  The map will now be initialized\nthe first time the function is called, which removes the undefiend\nbehaviour.\n\nThe same problem exists for the expedited_registers global, however\nthis global can just be made into a function local instead.  The\nexpedited_registers variable is used to build a pointer list which is\nthen passed to init_target_desc, however init_target_desc copies the\nvalues it is given so expedited_registers does not need to live longer\nthan its containing function.\n\nOn most of the AArch64 machines I have access too tracing is not\nsupported, and so the gdb.trace/*.exp tests that use the IPA just exit\nearly reporting unsupported.  I\u0027ve added a test which links an\ninferior with the IPA and just starts the inferior.  No tracing is\nperformed.  This exposes the current issue even on hosts that don\u0027t\nsupport tracing.  After this patch the test passes.\n",
  "tree_diff": [
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "bbcfb01316ee4628c354bc61076836145e6bcb41",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.trace/basic-libipa.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "e28f61e5f968913fbe3f3ee07c28c244a9f18fea",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.trace/basic-libipa.exp"
    },
    {
      "type": "modify",
      "old_id": "0ed9a42cbff6f84e555f77537c19b516fb0feef7",
      "old_mode": 33188,
      "old_path": "gdbserver/linux-aarch64-tdesc.cc",
      "new_id": "5d3b6ddffffae9d1d0e64f618b46bc6dc78a62f1",
      "new_mode": 33188,
      "new_path": "gdbserver/linux-aarch64-tdesc.cc"
    }
  ]
}
