On 11-10-16 03:21 PM, Jan Kratochvil wrote: > On Fri, 30 Sep 2011 21:31:33 +0200, Aleksandar Ristovski wrote: >> * solib-svr4.c (read_program_header): If PT_PHDR is present, use it >> to calculate correct address in case of PIE. > > FSF ChangeLog should describe the changes, not their reason. Therefore: > * solib-svr4.c (read_program_header): New variable pt_phdr, initialize > it from target PT_PHDR p_vaddr, relocate sect_addr by it. Change log changed (see below). >> >> + pt_phdr = (CORE_ADDR)-1; /* Address of the first entry. If not PIE, >> + this will be zero. >> + For PIE, it will be unrelocated at_phdr. */ > > There is CORE_ADDR_MAX. But I would prefer new `int pt_phdr_p' as "predicate" > boolean flag for valid pt_phdr value, these special values are fragile and one > has to think whether they can happen. pt_phdr_p introduced. Also, pt_phdr initialized to 0 even though not strictly necessary, but gcc complained about possible uninitialized use. > > >> + >> /* Find the requested segment. */ >> if (type == -1) >> { >> @@ -427,6 +431,11 @@ read_program_header (int type, int *p_se >> return 0; >> >> if (extract_unsigned_integer ((gdb_byte *)phdr.p_type, >> + 4, byte_order) == PT_PHDR) >> + pt_phdr = extract_unsigned_integer ((gdb_byte *)phdr.p_vaddr, >> + 4, byte_order); >> + >> + if (extract_unsigned_integer ((gdb_byte *)phdr.p_type, >> 4, byte_order) == type) > > That p_type could be decoded only once. Also any casta are `(type) val' with > a space accoridng to GCS (GNU Coding Standards). Cast fixed, p_type decoded only once. >> if (target_read_memory (sect_addr, buf, sect_size)) > > > Just about the style, I do not see any problems of the patch, thanks. > > Wrote the testcase, it is probably GNU/Linux-specific. I was contemplating a testcase but I couldn't think of a trick to "make" gdb not find the executable... Thanks for the test. > > I would like to review yet the changes. Revised patch attached. Thanks, Aleksandar New change log: Aleksandar Ristovski * solib-svr4.c (read_program_header): New variable pt_phdr, initialize it from target PT_PHDR p_vaddr, relocate sect_addr by it.