From: Maynard J. <may...@us...> - 2008-01-08 23:49:33
|
Update of /cvsroot/oprofile/oprofile/opjitconv In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv8576/opjitconv Modified Files: Tag: JIT_SUPPORT create_bfd.c jitsymbol.c opjitconv.h parse_dump.c Log Message: Add a VMA parameter to op_write_native_code Index: create_bfd.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/opjitconv/Attic/create_bfd.c,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -u -p -d -r1.1.2.9 -r1.1.2.10 --- create_bfd.c 10 Dec 2007 23:40:47 -0000 1.1.2.9 +++ create_bfd.c 8 Jan 2008 23:49:37 -0000 1.1.2.10 @@ -46,7 +46,7 @@ static int fill_symtab(void) s->name = e->symbol_name; s->section = section; s->flags = BSF_GLOBAL | BSF_FUNCTION; - s->value = e->code_addr - section->vma; + s->value = e->vma - section->vma; verbprintf(debug,"add sym: name=%s, value=%llx\n", s->name, (unsigned long long)s->value); syms[i] = s; @@ -96,13 +96,14 @@ error: static int create_text_section(int start_idx, int end_idx) { int rc = OP_JIT_CONV_OK; + asection * section; char const * section_name; int idx = start_idx; unsigned long long vma_start = - entries_address_ascending[start_idx]->code_addr; + entries_address_ascending[start_idx]->vma; struct jitentry * ee = entries_address_ascending[end_idx]; - unsigned long long vma_end = ee->code_addr + ee->code_size; + unsigned long long vma_end = ee->vma + ee->code_size; int size = vma_end - vma_start; section_name = bfd_get_unique_section_name(cur_bfd, ".text", &idx); @@ -110,7 +111,7 @@ static int create_text_section(int start idx, section_name, vma_start, size); section = create_section(cur_bfd, section_name, size, vma_start, - SEC_ALLOC|SEC_LOAD|SEC_READONLY|SEC_CODE|SEC_HAS_CONTENTS); + SEC_ALLOC|SEC_LOAD|SEC_READONLY|SEC_CODE|SEC_HAS_CONTENTS); if (section) entries_address_ascending[start_idx]->section = section; else @@ -139,25 +140,26 @@ static int fill_text_section_content(ase { int rc = OP_JIT_CONV_OK; unsigned long long vma_start = - entries_address_ascending[start_idx]->code_addr; + entries_address_ascending[start_idx]->vma; struct jitentry const * e; int i; for (i = start_idx; i <= end_idx; i++) { e = entries_address_ascending[i]; verbprintf(debug, "section = %s, i = %i, code = %llx," - " code_addr = %llx, offset = %llx," + " vma = %llx, offset = %llx," "size = %i, name = %s\n", section->name, i, (unsigned long long) (uintptr_t) e->code, - e->code_addr, e->code_addr - vma_start, + e->vma, e->vma - vma_start, e->code_size, e->symbol_name); /* the right part that is created by split_entry may - * have no code. + * have no code; also, the agent may have passed NULL + * for the code location. */ if (e->code) { rc = fill_section_content(cur_bfd, section, - e->code, (file_ptr) (e->code_addr - vma_start), + e->code, (file_ptr) (e->vma - vma_start), (bfd_size_type)e->code_size); if (rc != OP_JIT_CONV_OK) break; @@ -183,10 +185,10 @@ int partition_sections(void) for (j = 1; j < entry_count; j++) { entry = entries_address_ascending[j]; pred = entries_address_ascending[j - 1]; - end_addr = pred->code_addr + pred->code_size; + end_addr = pred->vma + pred->code_size; // calculate gap between code, if it is more than one page // create an additional section - if ((entry->code_addr - end_addr) >= 4096) { + if ((entry->vma - end_addr) >= 4096) { rc = create_text_section(i, j - 1); if (rc == OP_JIT_CONV_FAIL) goto out; @@ -211,11 +213,14 @@ int fill_sections(void) rc = fill_symtab(); if (rc == OP_JIT_CONV_FAIL) goto out; + + verbprintf(debug, "opjitconv: fill_sections\n"); i = 0; for (j = 1; j < entry_count; j++) { if (entries_address_ascending[j]->section) { section = entries_address_ascending[i]->section; - rc = fill_text_section_content(section, i, j - 1); + rc = fill_text_section_content(section, i, + j - 1); if (rc == OP_JIT_CONV_FAIL) goto out; i = j; @@ -224,7 +229,8 @@ int fill_sections(void) // this holds always if we have at least one jitentry if (i < entry_count) { section = entries_address_ascending[i]->section; - rc = fill_text_section_content(section, i, entry_count - 1); + rc = fill_text_section_content(section, + i, entry_count - 1); } out: return rc; Index: jitsymbol.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/opjitconv/Attic/jitsymbol.c,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -u -p -d -r1.1.2.9 -r1.1.2.10 --- jitsymbol.c 10 Dec 2007 23:40:47 -0000 1.1.2.9 +++ jitsymbol.c 8 Jan 2008 23:49:37 -0000 1.1.2.10 @@ -74,9 +74,9 @@ static int cmp_address(void const * a, v { struct jitentry * a0 = *(struct jitentry **) a; struct jitentry * b0 = *(struct jitentry **) b; - if (a0->code_addr < b0->code_addr) + if (a0->vma < b0->vma) return -1; - if (a0->code_addr == b0->code_addr) + if (a0->vma == b0->vma) return 0; return 1; } @@ -92,7 +92,7 @@ static void resort_address(void) // lower entry_count if entries are invalidated for (i = 0; i < entry_count; ++i) { - if (entries_address_ascending[i]->code_addr) + if (entries_address_ascending[i]->vma) break; } @@ -158,14 +158,14 @@ static char * replacement_name(char * s, /* * Mark the entry so it is not included in the ELF file. We do this by - * writing a 0 address as magic code_addr and sorting + * writing a 0 address as magic vma and sorting * it out later */ static void invalidate_entry(struct jitentry * e) { verbprintf(debug, "invalidate_entry: addr=%llx, name=%s\n", - e->code_addr, e->symbol_name); - e->code_addr = 0; + e->vma, e->symbol_name); + e->vma = 0; } @@ -234,10 +234,10 @@ static int select_one(int start_idx, int */ static void split_entry(struct jitentry * split, struct jitentry const * keep) { - unsigned long long start_addr_keep = keep->code_addr; - unsigned long long end_addr_keep = keep->code_addr + keep->code_size; - unsigned long long end_addr_split = split->code_addr + split->code_size; - unsigned long long start_addr_split = split->code_addr; + unsigned long long start_addr_keep = keep->vma; + unsigned long long end_addr_keep = keep->vma + keep->code_size; + unsigned long long end_addr_split = split->vma + split->code_size; + unsigned long long start_addr_split = split->vma; // do we need a right part? if (end_addr_split > end_addr_keep) { @@ -246,7 +246,7 @@ static void split_entry(struct jitentry char * s = xmalloc(strlen(split->symbol_name) + 3); strcpy(s, split->symbol_name); strcat(s, "#1"); - new_entry->code_addr = end_addr_keep; + new_entry->vma = end_addr_keep; new_entry->code_size = end_addr_split - end_addr_keep; new_entry->symbol_name = s; new_entry->sym_name_malloced = 1; @@ -257,8 +257,8 @@ static void split_entry(struct jitentry new_entry->code = NULL; verbprintf(debug, "split right (new) name=%s, start=%llx," " end=%llx\n", new_entry->symbol_name, - new_entry->code_addr, - new_entry->code_addr + new_entry->code_size); + new_entry->vma, + new_entry->vma + new_entry->code_size); insert_entry(new_entry); } // do we need a left part? @@ -272,8 +272,8 @@ static void split_entry(struct jitentry split->symbol_name = s; split->sym_name_malloced = 1; verbprintf(debug, "split left name=%s, start=%llx, end=%llx\n", - split->symbol_name, split->code_addr, - split->code_addr + split->code_size); + split->symbol_name, split->vma, + split->vma + split->code_size); } else { invalidate_entry(split); } @@ -292,8 +292,8 @@ static unsigned long long blank_overlaps unsigned long long retval; struct jitentry const * keep = entries_address_ascending[keep_idx]; struct jitentry * e; - unsigned long long start_addr_keep = keep->code_addr; - unsigned long long end_addr_keep = keep->code_addr + keep->code_size; + unsigned long long start_addr_keep = keep->vma; + unsigned long long end_addr_keep = keep->vma + keep->code_size; unsigned long long start_addr_entry, end_addr_entry; int i; unsigned long long min_start = keep->life_start; @@ -303,8 +303,8 @@ static unsigned long long blank_overlaps if (i == keep_idx) continue; e = entries_address_ascending[i]; - start_addr_entry = e->code_addr; - end_addr_entry = e->code_addr + e->code_size; + start_addr_entry = e->vma; + end_addr_entry = e->vma + e->code_size; if (debug) { if (!(start_addr_entry <= end_addr_entry)) { verbprintf(debug, "assert failed:" @@ -357,8 +357,8 @@ static int handle_overlap_region(int sta verbprintf(debug, "overlap idx=%i, name=%s, " "start=%llx, end=%llx, life_start=%lli, " "life_end=%lli, lifetime=%lli\n", - i, e->symbol_name, e->code_addr, - e->code_addr + e->code_size, e->life_start, + i, e->symbol_name, e->vma, + e->vma + e->code_size, e->life_start, e->life_end, e->life_end - e->life_start); } } @@ -425,11 +425,11 @@ static int scan_overlaps(void) * than [syms1, syms3] is correctly handled. */ a = entries_address_ascending[j - 1]; - end_addr2 = a->code_addr + a->code_size; + end_addr2 = a->vma + a->code_size; if (end_addr2 > end_addr) end_addr = end_addr2; a = entries_address_ascending[j]; - if (end_addr <= a->code_addr) { + if (end_addr <= a->vma) { if (i != j - 1) { if (handle_overlap_region(i, j - 1) == OP_JIT_CONV_FAIL) { Index: opjitconv.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/opjitconv/Attic/opjitconv.h,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -p -d -r1.1.2.10 -r1.1.2.11 --- opjitconv.h 10 Dec 2007 23:40:47 -0000 1.1.2.10 +++ opjitconv.h 8 Jan 2008 23:49:37 -0000 1.1.2.11 @@ -30,7 +30,7 @@ struct jitentry { /* linked list. see jitentry_list */ struct jitentry * next; /* vma */ - unsigned long long code_addr; + unsigned long long vma; /* point to code in the memory mapped file */ void const * code; /* size of the jitted code */ Index: parse_dump.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/opjitconv/Attic/parse_dump.c,v retrieving revision 1.1.2.11 retrieving revision 1.1.2.12 diff -u -p -d -r1.1.2.11 -r1.1.2.12 --- parse_dump.c 10 Dec 2007 23:40:47 -0000 1.1.2.11 +++ parse_dump.c 8 Jan 2008 23:49:37 -0000 1.1.2.12 @@ -29,7 +29,8 @@ static int parse_code_load(void const * int rc = OP_JIT_CONV_OK; char const * ptr = ptr_arg; struct jr_code_load const * rec = ptr_arg; - char const * end = ptr + size; + char const * end; + end = rec->code_addr ? ptr + size : NULL; entry = xcalloc(1, sizeof(struct jitentry)); @@ -40,12 +41,12 @@ static int parse_code_load(void const * entry->symbol_name = (char *)ptr; entry->sym_name_malloced = 0; ptr += strlen(ptr) + 1; - entry->code = ptr; - entry->code_addr = rec->code_addr; + entry->code = rec->code_addr ? ptr : NULL; + entry->vma = rec->vma; entry->code_size = rec->code_size; entry->section = NULL; entry->life_start = rec->timestamp; - // if nothing else is known the symbol lifes till the end of the + // if nothing else is known the symbol lives till the end of the // sampling run, this value may be overwritten by an unload record1 // later entry->life_end = end_time; @@ -54,11 +55,14 @@ static int parse_code_load(void const * entry->next = jitentry_list; jitentry_list = entry; - verbprintf(debug, "record0: name=%s, code_addr=%llx, code_size=%i, " + verbprintf(debug, "record0: name=%s, vma=%llx, code_size=%i, " "life_start=%lli, life_end=%lli\n", entry->symbol_name, - entry->code_addr, entry->code_size, entry->life_start, + entry->vma, entry->code_size, entry->life_start, entry->life_end); - if (ptr + entry->code_size + rec->pad_cnt != end) { + /* If end == NULL, the dump does not include code, and this sanity + * check is skipped. + */ + if (end && (ptr + entry->code_size + rec->pad_cnt != end)) { verbprintf(debug, "length mismatch"); rc = OP_JIT_CONV_FAIL; } @@ -76,13 +80,13 @@ static void parse_code_unload(void const struct jr_code_unload const * rec = ptr; struct jitentry * entry; - verbprintf(debug,"record1: code_addr=%llx, life_end=%lli\n", - rec->code_addr, rec->timestamp); + verbprintf(debug,"record1: vma=%llx, life_end=%lli\n", + rec->vma, rec->timestamp); /* FIXME: can we get a jr_code_unload with a zero time stamp or * a zero code address? */ - if (rec->timestamp > 0 && rec->code_addr != 0) { + if (rec->timestamp > 0 && rec->vma != 0) { for (entry = jitentry_list; entry; entry = entry->next) { - if (entry->code_addr == rec->code_addr && + if (entry->vma == rec->vma && entry->life_end == end_time) { entry->life_end = rec->timestamp; verbprintf(debug,"matching record found\n"); |