)]}'
{
  "commit": "fdf0ed6f7420cefec0131eab86ba54755245fee2",
  "tree": "ade34da338c958f75b10e955fb23e78e686d65cd",
  "parents": [
    "60d51dfed16480aef9c21690a1e1767c19dd9393"
  ],
  "author": {
    "name": "Nicolas Hillegeer",
    "email": "aktau@google.com",
    "time": "Wed Oct 09 07:44:18 2024 -0700"
  },
  "committer": {
    "name": "Gopher Robot",
    "email": "gobot@golang.org",
    "time": "Wed Oct 09 16:02:30 2024 +0000"
  },
  "message": "internal/gocore: support PIE ELF binaries\n\nGo binaries built with `-buildmode\u003dpie` are loaded at random addresses\n(ASLR) in memory by Linux.\n\nBefore this change, the mappings read from the `NT_NOTE` section of the\nELF binary matches the exe mappings:\n\n    # From NT_NOTE:\n    0x400000-0x491000             ----   593920 /tmp/TestVersionsgoroot#003207751013/001/test.exe+0x0\n    0x491000-0x54b000             ----   761856 /tmp/TestVersionsgoroot#003207751013/001/test.exe+0x91000\n    0x54b000-0x556000             ----    45056 /tmp/TestVersionsgoroot#003207751013/001/test.exe+0x14b000\n\n    # From executable:\n    0x400000-0x491000             r-xp   593920 /tmp/TestVersionsgoroot#003207751013/001/test.exe+0x0\n    0x491000-0x54b000             r--p   761856 /tmp/TestVersionsgoroot#003207751013/001/test.exe+0x91000\n    0x54b000-0x555000             rw-p    40960 /tmp/TestVersionsgoroot#003207751013/001/test.exe+0x14b000\n    0x555000-0x579000             rw-p   147456 anon+0x-440\n\n    # From core\n    0xc000000000-0xc000400000     rw-p  4194304 /tmp/TestVersionsgoroot#003207751013/001/core+0x32000\n    0x7f8b17c00000-0x7f8b19c00000 rw-p 33554432 /tmp/TestVersionsgoroot#003207751013/001/core+0x432000\n    0x7f8b29d80000-0x7f8b29d81000 rw-p     4096 /tmp/TestVersionsgoroot#003207751013/001/core+0x2432000\n    0x7f8b49d80000-0x7f8b49d81000 rw-p     4096 /tmp/TestVersionsgoroot#003207751013/001/core+0x2433000\n    0x7f8b5bc30000-0x7f8b5bc31000 rw-p     4096 /tmp/TestVersionsgoroot#003207751013/001/core+0x2434000\n    0x7f8b5e006000-0x7f8b5e007000 rw-p     4096 /tmp/TestVersionsgoroot#003207751013/001/core+0x2435000\n    0x7f8b5e466000-0x7f8b5e4c6000 rw-p   393216 /tmp/TestVersionsgoroot#003207751013/001/core+0x2436000\n    0x7f8b5e4c6000-0x7f8b5e5c6000 rw-p  1048576 /tmp/TestVersionsgoroot#003207751013/001/core+0x2496000\n    0x7f8b5e5c6000-0x7f8b5e5d7000 rw-p    69632 /tmp/TestVersionsgoroot#003207751013/001/core+0x2596000\n    0x7f8b5e657000-0x7f8b5e658000 rw-p     4096 /tmp/TestVersionsgoroot#003207751013/001/core+0x25a7000\n    0x7f8b5e6d7000-0x7f8b5e737000 rw-p   393216 /tmp/TestVersionsgoroot#003207751013/001/core+0x25a8000\n    0x7f8b5e737000-0x7f8b5e73b000 r--p    16384 /tmp/TestVersionsgoroot#003207751013/001/core+0x2608000\n    0x7f8b5e73b000-0x7f8b5e73d000 r-xp     8192 /tmp/TestVersionsgoroot#003207751013/001/core+0x260c000\n    0x7ffd88d3c000-0x7ffd88d5e000 rw-p   139264 /tmp/TestVersionsgoroot#003207751013/001/core+0x260e000\n\nAnd things worked fine. But, with PIE binaries, we see the following raw\naddresses when loading (e.g.):\n\n    # From NT_NOTE:\n    0x563f53d35000-0x563f53dc7000 ----   598016 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/test.exe+0x0\n    0x563f53dc7000-0x563f53e10000 ----   299008 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/test.exe+0x92000\n    0x563f53e10000-0x563f53ea3000 ----   602112 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/test.exe+0xdb000\n    0x563f53ea3000-0x563f53eaf000 ----    49152 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/test.exe+0x16e000\n    0x7ff5d0deb000-0x7ff5d0dec000 ----     4096 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2+0x0\n    0x7ff5d0dec000-0x7ff5d0e11000 ----   151552 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2+0x1000\n    0x7ff5d0e11000-0x7ff5d0e1b000 ----    40960 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2+0x26000\n    0x7ff5d0e1b000-0x7ff5d0e1f000 ----    16384 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2+0x30000\n\n    # From executable:\n    0x400000-0x492000             r-xp   598016 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/test.exe+0x0\n    0x492000-0x4db000             r--p   299008 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/test.exe+0x92000\n    0x4db000-0x56f000             rw-p   606208 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/test.exe+0xdb000\n    0x56f000-0x579000             rw-p    40960 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/test.exe+0x16f000\n    0x579000-0x59d000             rw-p   147456 anon+0x-460\n\n    # From core\n    0xc000000000-0xc000400000     rw-p  4194304 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/core+0x3000\n    0x563f53d35000-0x563f53d36000 r-xp     4096 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/core+0x403000\n    0x563f53d36000-0x563f53dc7000 r-xp   593920 anon+0x0\n    0x563f53dc7000-0x563f53e10000 r--p   299008 anon+0x0\n    0x563f53e10000-0x563f53ea3000 r--p   602112 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/core+0x404000\n    0x563f53ea3000-0x563f53eaf000 rw-p    49152 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/core+0x497000\n    0x563f53eaf000-0x563f53ed2000 rw-p   143360 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/core+0x4a3000\n    ...\n    0x7ff5d0deb000-0x7ff5d0dec000 r--p     4096 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/core+0x26a4000\n    0x7ff5d0dec000-0x7ff5d0e11000 r-xp   151552 anon+0x0\n    0x7ff5d0e11000-0x7ff5d0e1b000 r--p    40960 anon+0x0\n    0x7ff5d0e1b000-0x7ff5d0e1f000 rw-p    16384 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/core+0x26a5000\n    0x7fff34a26000-0x7fff34a48000 rw-p   139264 /tmp/TestVersionsgoroot-buildmode\u003dpie3327190927/001/core+0x26a9000\n\nThis caused two issues:\n\n 1. The mappings from the executable and the core were not unified\n    properly done in `addProgMappings -\u003e splicedMemory.Add` due to the\n    address ranges being different. Both existeded in the\n    `splicedMemory` set. Normally, the core mappings would override the\n    executable mappings when they overlap. To correct for this, add the\n    load offset (`staticBase`) to the executable addresses.\n 2. DWARF data (contained in the executable) references the base\n    addresses (for example, `allgs` is at 0x4003c4). Due to #1, a lookup\n    *would not crash*, but it would read the location from the\n    executable. In a PIE binary, such a lookup into the `.data` section\n    would be a relocation, and be present in the binary as all zeroes\n    (0x0). If #1 were fixed to offset by `staticBase` without fixing #2\n    would result in a read from unmapped memory.\n\nInspiration was taken from the Delve commit that added PIE support for\nmultiple platforms/architectures in\nhttps://github.com/go-delve/delve/commit/025d47c6e96e8ab5a2d2c142ae554e760cddabf8.\n\nAlso add tests that this works. I verified that if the changes from\nnon-test files are omitted, the test fails.\n\nChange-Id: Ifa08f71e7ed22320b78bc6015554e997b8ae521d\nReviewed-on: https://go-review.googlesource.com/c/debug/+/618977\nLUCI-TryBot-Result: Go LUCI \u003cgolang-scoped@luci-project-accounts.iam.gserviceaccount.com\u003e\nAuto-Submit: Nicolas Hillegeer \u003caktau@google.com\u003e\nReviewed-by: Michael Knyszek \u003cmknyszek@google.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "7890be5ceef8eccf683868d6e5ad6549ca23ace3",
      "old_mode": 33188,
      "old_path": "internal/core/process.go",
      "new_id": "74400e449e29c2453b2752356eeda380d6d458ac",
      "new_mode": 33188,
      "new_path": "internal/core/process.go"
    },
    {
      "type": "modify",
      "old_id": "967531a7a3036ce2500c3025d431280d91b960c2",
      "old_mode": 33188,
      "old_path": "internal/gocore/dwarf.go",
      "new_id": "e8f9497d492ab2c4c5941e4d48e60d30e8e40513",
      "new_mode": 33188,
      "new_path": "internal/gocore/dwarf.go"
    },
    {
      "type": "modify",
      "old_id": "91f69c1287a691360a7a68fff5167e012577a8f1",
      "old_mode": 33188,
      "old_path": "internal/gocore/gocore_test.go",
      "new_id": "8c8c58eb45f16f5e4f826afb79bbb70f40f51813",
      "new_mode": 33188,
      "new_path": "internal/gocore/gocore_test.go"
    }
  ]
}
