GOT and PLT references need a symbol; after all, they reference a GOT
or PLT slot. Thus, they need elf_add_gsym_reloc(). Mungify the
interface so that they can communicate the need for the PC-shifted
offset into the relocation.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
When generating an address that is *not* tied to a symbol, we just
want to emit the bytes. I believe the assembler is already supposed
to do that for us, but just in case, do it right here too.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
The x86-64 ABI wants the symbol addend to reside in the addend field
of the RELA relocation, not in the code stream. Apparently it's
something one can get away with, but the linker would still botch it
for some cases. Change it so we pass the proper output and emit zero
into the code stream.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Try to make the various GOT relocations do the right thing in ELF64,
including erring out when appropriate.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Expressions like
mov r15,[rel integer wrt ..got]
lea rax,[rel integer wrt ..gotoff]
now assemble correctly.
In addition, a fix has been made to the corresponding
abs relocations.
Both of these areas still need additional testing.
Somehow the win32 and win64 aliases got listed on Mach-O, not on
COFF. This doesn't have any effect on the current code, but might in
the future. Correct.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Don't use explicit L's for things which are really size_t; not only is
it unnecessarily ugly, but it's wrong in a lot of ways. Do some other
minor stylistic cleanups.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
We would leave the output symbol type uninitialized. Explicitly
initialize it to zero (T_NULL, meaning no symbol type information),
since that's what was effectively done.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
The testcase illustrates the problem. After "nasm -f obj
alonesym.nasm"
let's look to dump:
======
PUBDEF386(91) recnum:5, offset:0000005bh, len:03f9h, chksum:bbh(bb)
Group: 0, Seg: 1
00020000h - 'sym0000' Type:0
00020004h - 'sym0001' Type:0
....
00020134h - 'sym0077' Type:0
PUBDEF(90) recnum:6, offset:00000457h, len:000ah, chksum:b6h(b6)
Group: 0, Seg: 1
00000138h - 's' Type:2
0000b600h - '' Type:0
======
The problem is while 's' offset is 20138h it is marked as type 90h not
91h. The root cause is located in obj_x():
static ObjRecord *obj_x(ObjRecord * orp, uint32_t val)
{
if (orp->type & 1)
orp->x_size = 32;
if (val > 0xFFFF)
orp = obj_force(orp, 32);
if (orp->x_size == 32)
return (obj_dword(orp, val));
orp->x_size = 16;
return (obj_word(orp, val));
}
It sets up x_size and than writes data. In the testcase data are the
offset and this offset overflows a record. In this case the record is
emitted and its x_size is cleared. Because this is last PUBDEF the new
record with only 's' symbol is emitted also but its x_size is not 32
(it's still zero) so obj_fwrite doesn't switch to 91h type.
The problem seems to be very generic and expected to be occurred on
many other record types as well.
----
And the fix is simple:
if (orp->x_size == 32)
{
ObjRecord * nxt = obj_dword(orp, val);
nxt->x_size = 32; /* x_size is cleared when a record overflows */
return nxt;
}
ctype functions take an *int*, which the user is expected to have
taken the input character from getc() and friends, or taken a
character and cast it to (unsigned char).
We don't care about EOF (-1), so use macros that cast to (unsigned
char) for us.
Move the handling of "extra" macros (i.e. output format macros) into
the macros.pl mechanism. This allows us to change the format of the
internal macro store in the future - e.g. to a single byte store
without redundant pointers.
Also, stop using indicies into a long array when there is no good
reason to not just use different arrays.
Make the WSAA macros contain their own buffer definitions. This
eliminates the need to have a separate "workbuf" declared in the
outelf backends, which isn't even used for anything else, except for a
few completely redundant strcpys.
Note: these macros probably should be replaced with actual
functions. The overhead of the function call is likely to be more
than offset by lower icache footprint.
Guess what, SEH again, but in Win64 context, which is completely
different matter from Win32. At lowest level this one boils down to
putting so called imagerel references, or in practical terms
relocations of type ADDR32NB, 0x0003, into .pdata and .xdata
segments. Two possibilities. 1. implement say 'wrt ..imagerel' or 'wrt
..imagebase'. 2. silently enforce ADDR32NB relocations in .pdata and
.xdata segments.
This is basically not a bug report, but a feature request.
It's desired to be able to link .obj modules compiled with 'nasm -f
win32' with Microsoft 'link /safeseh'. As well as to register symbols
(commonly subroutine's entry points or even external symbols) as "safe
handlers." In order to achieve this, several points are required.
First of all, object module has to have absolute symbol named @feat.00
with value of 1. This can actually be achived by adding 'absolute 1'
and '@feat.00:' to source code, but it's desirable that it's
autogenerated for win32 modules.
Handler registration is essentially symbol's *index* in current
module's symbol table in .sxdata, segment with 0x200 segment flags, an
"info" segment. It's also essential that symbol has type 0x20 (see
below). All this is depicted in following framgents of 'objdump -xD'
output:
Sections:
Idx Name Size VMA LMA File off Algn
0 .sxdata 00000004 00000000 00000000 0000003c 2**2
CONTENTS, READONLY, DEBUGGING
SYMBOL TABLE:
...
[ 5](sec -1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000001 @feat.00
[ 6](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _handler
...
<.sxdata>
0: 06 00 00 00
Note [6] and (ty 20) in _handle line in SYMBOL TABLE. "06 00 00 00" in
.sxdata is little-endian 6, _handler's index. This is what makes up
"registration." It's impossible to achieve this with current nasm
facilities and it's probably appropriate to introduce a directive for
it, 'safeseh _handler' is probably most natural choice.
When using temporaries in macros, given them a unique prefix to avoid
namespace collisions when using one macro inside another.
Move the WSAA*() macros from outelf32/outelf64 to a separate header
file.
Clean up remaining build warnings. None of this should affect code
operations. The only warnings which were actually relevant might have
been the ones in ldrdf.c, but it's not clear if anyone ever uses that.
Fix one missed change from "type" to "size". May want to look through
all the other backends as well for similar issues.
This would generate the wrong section lengths, with obviously bad results.
Our size arguments are 64-bit values, but we don't need that range for
anywhere where we need a switch. OpenWatcom can't deal with them
(sigh), so cast them to (int) for now.
Address data is always int64_t even if the size itself is smaller;
this was broken on bigendian hosts (still need testing!)
Create simple "write sized object" macros.
Fix alignment handling in the Mach-O format. The patch is from the
bug report, mangled to apply to the current source base. I have no
way to test this, so I'm going to have to assume it's correct.
Don't combine type and size into a single argument; *every* backend
immediately breaks them apart, so it's really just a huge waste of
effort. Additionally, it avoids using short immediates in the
resulting code, which is a bad thing.
OpenWatcom doesn't like 64-bit switch arguments; the change to 64-bit
type arguments caused that to happen in outmacho.c. Hack around it
for now; however, realistically speaking the whole bit stealing thing
is probably a bad idea, especially since virtually all CPUs handle
short immediates better than long ones.
Proper use of bool and enum makes code easier to debug. Do more of
it. In particular, we really should stomp out any residual uses of
magic constants that aren't enums or, in some cases, even #defines.
Both C and C++ have "bool", "true" and "false" in lower case; C
requires <stdbool.h> for this, in C++ it is an inherent type built
into the compiler. Use those instead of the old macros; emulate with
a simple typedef enum if unavailable.
Concentrate compiler dependencies to compiler.h; make sure compiler.h
is included first in every .c file (since some prototypes may depend
on the presence of feature request macros.)
Actually use the conditional inclusion of various functions (totally
broken in previous releases.)
Per SF bug report 1351586:
The COFF spec suggests that the "Virtual Size" field (which
immediately follows the name field inside a section header) be set to
0 for an object file.
By contrast (as documented in comment #4 at the beginning of its
outcoff.c file) NASM sets it to a particular non-0 value.
MASM 6.15 matches NASM for both 16- and 32-bit object files,
i.e. emits non-0 values.
MASM 8 (from VS 2005 Beta) matches the COFF spec for 64-bit object
files, i.e. emits 0.
GAS matches the COFF spec for 32-bit object files (MinGW or Cygwin),
i.e. also emits 0.
Older versions of GNU ld seem to honor said "Virtual Size" field
whereas newer versions do not. As a result those older versions
generate "bloated" image files.
Since the COFF spec and the real world seem to disagree for this case,
it might make sense to add a method for selecting between the two to
NASM.
Date: 2005-11-28 15:39
Sender: nasm64developer
Logged In: YES
user_id=804543
MASM 8 (from VS 2005 Beta) also matches the COFF spec for 16- and
32-bit object files, i.e. emits 0.
That said, NASM should always emit 0 too. Therefore I am turning this
from a support request into a bug.
Minor fixes to make it possible to compile with MS Visual C++ 2005.
Unfortunately, MSVC++ is not fully C99 compliant; in particular, it
doesn't handle interspersed declarations and other code. Furthermore,
it chokes on some expressions in outelf64.c, which fortunately can be
easily substituted with simpler expressions.
Finish the perfect hash tokenizer, and actually enable it.
Move stdscan() et al to a separate file, since it's not needed in any
of the clients of nasmlib other than nasm itself.
Run make alldeps.
Move anything compiler-specific to "compiler.h".
There was an unguarded use of __attribute__(()) in outmacho.c; also
require gcc 4+ for __builtin_ctlz(). Speed up the open-coded version, too.
- Remove obsolete types like "uint32"; use "uint32_t" consistently.
- Make sure we include <inttypes.h> where needed.
- Header file guards should be FOO_H or SUBDIR_FOO_H; _FOO_H infringes
on the C implementation's namespace and should only be used when
writing libc!
- Change a few "int8_t" back to "char" where appropriate. There are
a lot more places where that should be done, though.
- Clean up the check for getuid/getgid in rdoff/rdlar.h.
Change symbols from saa to explicitly allocated.
macho_layout_symbols: new function to sort symbols and renumber.
adjust symtab output accordingly
fixup relocs after renumbering
add relocation debugging routines.
Export/import/common label size is increased from 33 to 64. Fixed the bug
that caused wrong behavior of rdfgetheaderrec() if label length was 32.
Changed error codes from numeric values to symbolic constants.
Moved some routines from rdfdump.c to rdoff.c. They will be utilized also
by rdfdisasm, which is being developed.