)]}'
{
  "commit": "545e49f5ee911bbcf55dc3dbeb49b62103b205d4",
  "tree": "88abf788f10a8b98d4d52b8da3a05aa26b95ec6a",
  "parents": [
    "9dec38d3b11c779e8f386050ed5046aaa4e759db"
  ],
  "author": {
    "name": "Tom de Vries",
    "email": "tdevries@suse.de",
    "time": "Tue Dec 07 08:07:18 2021 +0100"
  },
  "committer": {
    "name": "Tom de Vries",
    "email": "tdevries@suse.de",
    "time": "Tue Dec 07 08:07:18 2021 +0100"
  },
  "message": "[gdb/tdep] Fix inferior plt calls in PIE for i386\n\nConsider test-case test.c:\n...\nint main (void) {\n  void *p \u003d malloc (10);\n  return 0;\n}\n...\n\nWhen compiled to a non-PIE exec:\n...\n$ gcc -m32 test.c\n...\nthe call sequence looks like:\n...\n 8048447:       83 ec 0c                sub    $0xc,%esp\n 804844a:       6a 0a                   push   $0xa\n 804844c:       e8 bf fe ff ff          call   8048310 \u003cmalloc@plt\u003e\n...\nwhich calls to:\n...\n08048310 \u003cmalloc@plt\u003e:\n 8048310:       ff 25 0c a0 04 08       jmp    *0x804a00c\n 8048316:       68 00 00 00 00          push   $0x0\n 804831b:       e9 e0 ff ff ff          jmp    8048300 \u003c.plt\u003e\n...\nwhere the first insn at 0x8048310 initially jumps to the following address\n0x8048316, read from the .got.plt @ 0x804a00c:\n...\n 804a000 0c9f0408 00000000 00000000 16830408  ................\n 804a010 26830408                             \u0026...\n...\n\nLikewise, when compiled as a PIE:\n...\n$ gcc -m32 -fPIE -pie test.c\n...\nwe have this call sequence (with %ebx setup to point to the .got.plt):\n...\n0000055d \u003cmain\u003e:\n 579:   83 ec 0c                sub    $0xc,%esp\n 57c:   6a 0a                   push   $0xa\n 57e:   89 c3                   mov    %eax,%ebx\n 580:   e8 6b fe ff ff          call   3f0 \u003cmalloc@plt\u003e\n...\nwhich calls to:\n...\n000003f0 \u003cmalloc@plt\u003e:\n 3f0:   ff a3 0c 00 00 00       jmp    *0xc(%ebx)\n 3f6:   68 00 00 00 00          push   $0x0\n 3fb:   e9 e0 ff ff ff          jmp    3e0 \u003c.plt\u003e\n...\nwhere the insn at 0x3f0 initially jumps to following address 0x3f6, read from\nthe .got.plt at offset 0xc:\n...\n 2000 f41e0000 00000000 00000000 f6030000  ................\n 2010 06040000                             ....\n...\n\nWhen instead doing an inferior call to malloc (with nosharedlib to force\nmalloc to resolve to malloc@plt rather than the functions in ld.so or libc.so)\nwith the non-PIE exec, we have the expected:\n...\n$ gdb -q -batch a.out -ex start -ex nosharedlib -ex \"p /x (void *)malloc (10)\"\nTemporary breakpoint 1 at 0x8048444\n\nTemporary breakpoint 1, 0x08048444 in main ()\n$1 \u003d 0x804b160\n...\n\nBut with the PIE exec, we run into:\n...\n$ gdb -q -batch a.out -ex start -ex nosharedlib -ex \"p /x (void *)malloc (10)\"\nTemporary breakpoint 1 at 0x56c\n\nTemporary breakpoint 1, 0x5655556c in main ()\n\nProgram received signal SIGSEGV, Segmentation fault.\n0x565553f0 in malloc@plt ()\n...\n\nThe segfault happens because:\n- the inferior call mechanism doesn\u0027t setup %ebx\n- %ebx instead is 0\n- the jump to \"*0xc(%ebx)\" reads from memory at 0xc\n\nFix this by setting up %ebx properly in i386_thiscall_push_dummy_call.\n\nFixes this failure with target board unix/-m32/-pie/-fPIE reported in\nPR28467:\n...\nFAIL: gdb.base/nodebug.exp: p/c (int) array_index(\"abcdef\",2)\n...\n\nTested on x86_64-linux, with target board unix/-m32 and unix/-m32/-fPIE/-pie.\n\nBug: https://sourceware.org/bugzilla/show_bug.cgi?id\u003d28467\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "ce18cf3e9be3274073a94e58656b5f2a7dcb280d",
      "old_mode": 33188,
      "old_path": "gdb/i386-tdep.c",
      "new_id": "7bb0dd4b7395d96d484773c01df1b97fdd7e7328",
      "new_mode": 33188,
      "new_path": "gdb/i386-tdep.c"
    },
    {
      "type": "modify",
      "old_id": "e03abfacdae73263e89e76151eb9478455cc3e68",
      "old_mode": 33188,
      "old_path": "gdb/maint.c",
      "new_id": "4eb983845800340be591a03ec2774cddc6d6d15c",
      "new_mode": 33188,
      "new_path": "gdb/maint.c"
    },
    {
      "type": "modify",
      "old_id": "d3c0122a3212dd0057213d1e6d238a5d7dae4309",
      "old_mode": 33188,
      "old_path": "gdb/maint.h",
      "new_id": "81b3beb703d1d5fb53fca6011bb185f07912e2d1",
      "new_mode": 33188,
      "new_path": "gdb/maint.h"
    }
  ]
}
