{"action":"closed","issue":{"url":"https://api.github.com/repos/martinribelotta/elfloader/issues/1","repository_url":"https://api.github.com/repos/martinribelotta/elfloader","labels_url":"https://api.github.com/repos/martinribelotta/elfloader/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/martinribelotta/elfloader/issues/1/comments","events_url":"https://api.github.com/repos/martinribelotta/elfloader/issues/1/events","html_url":"https://github.com/martinribelotta/elfloader/issues/1","id":207139869,"number":1,"title":"How to read Text section，I can't understand the  Elf32_Rel struct!","user":{"login":"joeweiming","id":3240994,"avatar_url":"https://avatars.githubusercontent.com/u/3240994?v=3","gravatar_id":"","url":"https://api.github.com/users/joeweiming","html_url":"https://github.com/joeweiming","followers_url":"https://api.github.com/users/joeweiming/followers","following_url":"https://api.github.com/users/joeweiming/following{/other_user}","gists_url":"https://api.github.com/users/joeweiming/gists{/gist_id}","starred_url":"https://api.github.com/users/joeweiming/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joeweiming/subscriptions","organizations_url":"https://api.github.com/users/joeweiming/orgs","repos_url":"https://api.github.com/users/joeweiming/repos","events_url":"https://api.github.com/users/joeweiming/events{/privacy}","received_events_url":"https://api.github.com/users/joeweiming/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-02-13T07:21:34Z","updated_at":"2017-02-17T14:49:21Z","closed_at":"2017-02-17T14:49:21Z","body":"Hi, Thanks for your code, these days, I have a project to need load the elf file for my arm product, it is base the MTK sdk without MMU. \r\nbut when I read your code, somewhere I  can't understand. Like this function:\r\n\r\nstatic int relocate(ELFExec_t *e, Elf32_Shdr *h, ELFSection_t *s,\r\n    const char *name) {\r\n  if (s->data) {\r\n    Elf32_Rel rel;\r\n    size_t relEntries = h->sh_size / sizeof(rel);\r\n    size_t relCount;\r\n    (void) LOADER_SEEK_FROM_START(e->fd, h->sh_offset);\r\n    DBG(\" Offset   Info     Type             Name\\n\");\r\n    //重定位节中的数据\r\n    for (relCount = 0; relCount < relEntries; relCount++) {\r\n      if (LOADER_READ(e->fd, &rel, sizeof(rel)) == sizeof(rel)) {\r\n        Elf32_Sym sym;\r\n        Elf32_Addr symAddr;\r\n\r\n        char name[33] = \"<unnamed>\";\r\n        int symEntry = ELF32_R_SYM(rel.r_info);\r\n        int relType = ELF32_R_TYPE(rel.r_info);\r\n        Elf32_Addr relAddr = ((Elf32_Addr) s->data) + rel.r_offset;\r\n\r\n        readSymbol(e, symEntry, &sym, name, sizeof(name));\r\n        DBG(\" %08X %08X %-16s %s\\n\", rel.r_offset, rel.r_info, typeStr(relType),\r\n            name);\r\n\r\n        symAddr = addressOf(e, &sym, name);\r\n        if (symAddr != 0xffffffff) {\r\n          DBG(\"  symAddr=%08X relAddr=%08X\\n\", symAddr, relAddr);\r\n          if (relocateSymbol(relAddr, relType, symAddr) == -1)\r\n            return -1;\r\n        } else {\r\n          DBG(\"  No symbol address of %s\\n\", name);\r\n          return -1;\r\n        }\r\n      }\r\n    }\r\n    return 0;\r\n  } else\r\n    MSG(\"Section not loaded\");\r\n  return -1;\r\n}\r\n\r\nit is like the text. data. bass section is all the same struct with the struct below.\r\ntypedef struct\r\n{\r\n  Elf32_Addr   r_offset;\r\n  Elf32_Word   r_info;\r\n} Elf32_Rel;\r\nI read my elf file,\r\n![image](https://cloud.githubusercontent.com/assets/3240994/22874242/f586edca-f1ff-11e6-99eb-b04bf23153de.png)\r\ndata like this picture, it is ER_RO section, so ,how I relocate this ? I can't understand this format!\r\nthank you!\r\n"}}
{"actor":{"display_login":"martinribelotta"}}