summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChang S. Bae <chang.seok.bae@intel.com>2017-04-22 06:40:43 -0700
committerH. Peter Anvin <hpa@zytor.com>2017-04-23 16:46:45 -0700
commit4dfbd9aec56577d7e0dc9398781ea9918dbdcbf6 (patch)
tree59e57870194240a5a6e0e1ef517277a089cdf926
parent9f94136c33d4c3e7bb220d5abe7016c946e5916c (diff)
downloadnasm-4dfbd9aec56577d7e0dc9398781ea9918dbdcbf6.tar.gz
macho: add file path to the dwarf debugging output
Apple's linker requires file path along with file name to produce debug notes. Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r--output/outmacho.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/output/outmacho.c b/output/outmacho.c
index 173706b9..5c259e2f 100644
--- a/output/outmacho.c
+++ b/output/outmacho.c
@@ -1784,7 +1784,7 @@ static void macho_dbg_generate(void)
size_t saa_len = 0, high_addr = 0, total_len = 0;
struct section *p_section = NULL;
/* calculated at debug_str and referenced at debug_info */
- uint32_t producer_str_offset = 0, module_str_offset = 0;
+ uint32_t producer_str_offset = 0, module_str_offset = 0, path_str_offset = 0;
/* debug section defines */
{
@@ -1886,7 +1886,8 @@ static void macho_dbg_generate(void)
struct file_list *p_file = dw_head_list;
uint32_t idx = 0;
struct SAA *p_str = saa_init(1L);
- nasm_assert(p_str != NULL);
+ struct SAA *p_path_str = saa_init(1L);
+ nasm_assert((p_str != NULL) && (p_path_str != NULL));
p_section = get_section_by_name("__DWARF", "__debug_str");
nasm_assert(p_section != NULL);
@@ -1894,19 +1895,33 @@ static void macho_dbg_generate(void)
producer_str_offset = 0;
saa_wbytes(p_str, nasm_signature, strlen(nasm_signature) + 1);
- module_str_offset = producer_str_offset + strlen(nasm_signature) + 1;
+ module_str_offset = path_str_offset = producer_str_offset + strlen(nasm_signature) + 1;
+
for(; idx < dw_num_files; idx++) {
- saa_wbytes(p_str, p_file->file_name, (int32_t)(strlen(p_file->file_name) + 1));
+ size_t cur_file_strlen = strlen(p_file->file_name) + 1;
+ char *cur_path = nasm_realpath(p_file->file_name);
+ size_t cur_path_strlen = strlen(cur_path);
+
+ nasm_assert(cur_path_strlen > cur_file_strlen);
+ cur_path_strlen -= cur_file_strlen;
+ cur_path[cur_path_strlen] = '\0';
+ saa_wbytes(p_str, p_file->file_name, cur_file_strlen);
+ saa_wbytes(p_path_str, cur_path, cur_path_strlen);
+ path_str_offset += cur_file_strlen;
p_file = p_file->next;
}
saa_len = p_str->datalen;
-
p_buf = nasm_malloc(saa_len);
saa_rnbytes(p_str, p_buf, saa_len);
macho_output(p_section->index, p_buf, OUT_RAWDATA, saa_len, NO_SEG, 0);
-
saa_free(p_str);
+
+ saa_len = p_path_str->datalen;
+ p_buf = nasm_malloc(saa_len);
+ saa_rnbytes(p_path_str, p_buf, saa_len);
+ macho_output(p_section->index, p_buf, OUT_RAWDATA, saa_len, NO_SEG, 0);
+ saa_free(p_path_str);
}
/* debug info */
@@ -1927,6 +1942,7 @@ static void macho_dbg_generate(void)
saa_write32(p_info, producer_str_offset); /* offset from string table for DW_AT_producer */
saa_write16(p_info, DW_LANG_Mips_Assembler); /* DW_AT_language */
saa_write32(p_info, module_str_offset); /* offset from string table for DW_AT_name */
+ saa_write32(p_info, path_str_offset); /* offset from string table for DW_AT_comp_dir */
saa_write32(p_info, 0); /* DW_AT_stmt_list */
if (ofmt == &of_macho64) {
@@ -1980,6 +1996,9 @@ static void macho_dbg_generate(void)
saa_write8(p_abbrev, DW_AT_name);
saa_write8(p_abbrev, DW_FORM_strp);
+ saa_write8(p_abbrev, DW_AT_comp_dir);
+ saa_write8(p_abbrev, DW_FORM_strp);
+
saa_write8(p_abbrev, DW_AT_stmt_list);
saa_write8(p_abbrev, DW_FORM_data4);