macho/reloc: Fixed in handling GOT/GOTLOAD/TLV relocations

- Changed to search all symbols, instead of only global symbols.

- Will do immediate exits when unsupported use of WRT

- Fixed to mark (got)pcrel flag only for macho64 output. GOT is
supported only for 64-bit.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
This commit is contained in:
Chang S. Bae 2018-10-08 18:49:51 -07:00 committed by Cyrill Gorcunov
parent 4cbbb3940d
commit e859ece378

View File

@ -569,18 +569,22 @@ static int64_t add_reloc(struct section *sect, int32_t section,
goto needsym;
needsym:
r->pcrel = 1;
r->pcrel = (fmt.ptrsize == 8 ? 1 : 0);
if (section == NO_SEG) {
nasm_error(ERR_NONFATAL, "Unsupported use of use of WRT");
goto bail;
} else if (fi == NO_SECT) {
/* external */
r->snum = raa_read(extsyms, section);
} else {
/* internal - does it really need to be global? */
struct symbol *sym = macho_find_sym(s, offset, true,
reltype != RL_TLV);
if (!sym)
/* internal - GOTPCREL doesn't need to be in global */
struct symbol *sym = macho_find_sym(s, offset,
false, /* reltype != RL_TLV */
true);
if (!sym) {
nasm_error(ERR_NONFATAL, "Symbol for WRT not found");
goto bail;
}
r->snum = sym->initial_snum;
}