Commit graph

139 commits

Author SHA1 Message Date
Peter Johnson
2cd3bb50e2
elf.c: Fix NULL deref on bad xsize expression (#234) 2023-06-30 08:08:55 -07:00
Biswapriyo Nath
f79f5e37f0
Fix function declaration warnings with clang (#226)
This fixes the following compiler warnings with clang

tools/genperf/perfect.c:65:6: warning: a function definition without a prototype
is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]

frontends/yasm/yasm.c:1379:23: warning: a function declaration without a prototype
is deprecated in all versions of C [-Wstrict-prototypes]

modules/objfmts/elf/elf.c:225:18: warning: a function declaration without a prototype
is deprecated in all versions of C [-Wstrict-prototypes]
2023-05-17 15:23:32 -07:00
kalebskeithley
0799f381d5
Update elf-objfmt.c (#148) 2023-05-12 21:15:02 -07:00
liuxiang88
bfe1bc257d
Add EM for loongarch (#192) 2023-05-12 21:08:50 -07:00
Peter Johnson
00c85278d1 Warnings cleanup. 2014-08-10 11:39:20 -07:00
Peter Johnson
c3aa2478c6 Unbreak distcheck. 2013-06-21 10:03:05 -07:00
H.J. Lu
510c8dd7e6 Add support for x32
X32 is a 32-bit psABI for x86-64 with 32-bit pointer size.  More info
can be found at:

https://sites.google.com/site/x32abi/
2012-08-30 23:47:41 -07:00
Scott Graham
51b1f7ef98 fix a couple warnings when building on win32 2012-05-09 20:48:16 -07:00
Peter Johnson
94ab1135a3 Remove $Id$ and RCSID() usage.
These are useless now that we're using git.
2011-08-19 10:43:16 -07:00
Peter Johnson
502eebd339 Fix const warning in elf_machine_ssym usage.
Reported by: Pierre Muller

[#237 state:resolved]
2011-08-19 10:21:10 -07:00
Peter Johnson
de38127f1c Fix "times" relocation handling.
Previously a line such as "times 4 mov rax, [rel foobar]" would result
in incorrect relocations being generated.

Patch by: bird-yasm@anduin.net

[#211 state:resolved]
2011-06-25 23:32:22 -07:00
Peter Johnson
d5ae195703 Fix #202 (incorrect GOT offset generated in NASM mode).
Don't generate an additional offset for _GLOBAL_OFFSET_TABLE_ if a WRT was
specified (the NASM usage).  In GAS, _GLOBAL_OFFSET_TABLE_ doesn't have a WRT
but instead has special handling.

This isn't quite *exactly* the right fix; a better fix would be to recognize
the _GLOBAL_OFFSET_TABLE_ case in the GAS parser and adjust the value
appropriately there.  However, this fix seems to do the right thing in the
meantime for both GAS and NASM cases.

svn path=/trunk/yasm/; revision=2321
2010-05-15 07:45:48 +00:00
Peter Johnson
323153d55a Instead of initializing unknown sections en-masse during objfmt_output(),
add new objfmt interface function init_new_section() to initialize as we
go.

This fixes several issues, primarily with debug formats that create sections.

Reported by: Brian Gladman

svn path=/trunk/yasm/; revision=2310
2010-03-28 19:28:54 +00:00
Peter Johnson
c2dce0a354 Update elf special symbols:
- Add tlsdesc and tlscall to both x86 and amd64.
 - Add 64-bit pltoff, gotplt, gotoff to amd64.

svn path=/trunk/yasm/; revision=2210
2009-07-22 05:51:35 +00:00
Peter Johnson
948d59417b Unbreak make check (broken by [2206]).
svn path=/trunk/yasm/; revision=2209
2009-07-22 05:49:54 +00:00
Peter Johnson
fbb1fd248d elf: Add latest x86 relocation types.
svn path=/trunk/yasm/; revision=2208
2009-07-22 05:45:03 +00:00
Peter Johnson
0f373ef2ae elf: Add support for 64-bit PC-relative relocation.
svn path=/trunk/yasm/; revision=2207
2009-07-21 06:49:44 +00:00
Peter Johnson
6f329fb107 Special-case _GLOBAL_OFFSET_TABLE_ in elf32/64 to generate appropriate relocs.
This was particularly noticable in GAS, but there was also a bug in NASM
output (lack of fixup within instruction in elf32).

Also:
- changed ssym lookup from a linear search to using assocdata
- added more relocation types (most not implemented)

Reported by: Mark Charney

svn path=/trunk/yasm/; revision=2206
2009-07-21 06:48:42 +00:00
Peter Johnson
b7a38ed4fd Allow @ signs in identifiers in win32/win64 only.
In ELF, @ is used to indicate special relocations.

Fixes #164.

Reported by: Gregory McGarry on yasm-devel@
Testcase by: Gregory McGarry

We don't allow identifiers to start with @; doing so conflicts with use of
e.g. "@function" in some directives.  Need to look into what GAS does.

svn path=/trunk/yasm/; revision=2166
2009-01-02 08:33:21 +00:00
Peter Johnson
f8113755e5 elf-x86id.asm testcase: Don't require NASM preproc.
svn path=/trunk/yasm/; revision=2165
2009-01-02 08:15:58 +00:00
Peter Johnson
63e1873a8e Don't require nasm preproc for some testcases.
svn path=/trunk/yasm/; revision=2129
2008-10-07 04:34:19 +00:00
Peter Johnson
4d78c310b5 elf64: automatically promote [rel foo wrt ..gotpc] to GOTPCREL relocation.
Formerly, [rel foo wrt ..gotpcrel] was required.

svn path=/trunk/yasm/; revision=2126
2008-10-03 08:13:00 +00:00
Peter Johnson
e0d651acdd Fix extraneous warnings and update testcases for [2114] changes.
svn path=/trunk/yasm/; revision=2115
2008-07-08 06:36:44 +00:00
Peter Johnson
dbf6c6ce38 Fix #148: Don't clear elf section flags in GAS if it's a standard section and
no GAS flags were provided.

svn path=/trunk/yasm/; revision=2114
2008-07-08 06:28:37 +00:00
Peter Johnson
53b2d01a77 Fix #132: Add --prefix and --suffix (aka --postfix) options.
These allow arbitrary prefixes and/or suffixes to be added to
externally-visible (GLOBAL, EXTERN, or COMMON) symbol names.

svn path=/trunk/yasm/; revision=2109
2008-06-08 09:06:05 +00:00
Peter Johnson
b7f2fbc64f Add cmake build infrastructure.
Not default nor even distributed in the .tar.gz, the cmake build allows for
loadable yasm plugins by building libyasm as a shared library.
Example plugins are in the plugins/ directory, and may be loaded into a
cmake-built yasm using the -N command line option (non-cmake builds will
not have this option).

Tested only on Linux so far, but should be relatively painless to port to
Windows thanks to the use of cmake rather than libtool to create shared
libraries.

The only modification to the main source tree is some conditional-compiled
additions to yasm.c.

svn path=/trunk/yasm/; revision=2098
2008-05-22 09:08:03 +00:00
Peter Johnson
cbf0c7befd Split NASM preprocessor standard macro set between various modules.
Standard macro sets are looked up based on parser and preprocessor keyword
from individual modules.

The "standard" NASM parser macros now reside in the NASM parser, so when
the GAS parser is used with the NASM preprocessor, the NASM-specific macros
are no longer defined.

Object-format specific macros are now individually defined by each object
formatm module.  This allows for the object formats to be independent of the
NASM preprocessor module and yields a small optimization benefit as unused
object format macros don't need to be skipped over.

Also add GAS macro equivalents for the Win64 SEH more complex directives [1].

[1] Requested by Brian Gladman <brg@gladman.plus.com>

svn path=/trunk/yasm/; revision=2082
2008-05-09 06:46:02 +00:00
Peter Johnson
6ced647e97 Allow setting of the TLS section flag in the NASM section directive.
Also default the .tdata section to having the TLS flag set.

svn path=/trunk/yasm/; revision=2041
2008-02-21 09:00:46 +00:00
Peter Johnson
b49c080965 Set ELF symbol type to TLS if either:
- symbol is defined in a TLS section
- symbol is used in a TLS relocation

This is required by the GNU linker, and matches GNU as behavior.
The implementation is not as clean as it perhaps should be, but it does
the job.

Reported by: Nils Weller <nils@gnulinux.nl>

svn path=/trunk/yasm/; revision=2040
2008-02-21 08:57:23 +00:00
Peter Johnson
fea08b7307 Update ..sym to work within new get_special_sym() framework.
svn path=/trunk/yasm/; revision=2037
2008-02-09 04:09:47 +00:00
Peter Johnson
a3e30bc39f Add support for ELF32 and ELF64 TLS (thread local storage) relocations.
While here, simplify how special relocations are handled inside ELF.

Requested by: Nils Weller <nils@gnulinux.nl>

svn path=/trunk/yasm/; revision=2036
2008-02-09 04:06:47 +00:00
Peter Johnson
04039380d1 Enable use of sym@FOO constructs in GAS parser.
To do this, restructure how special symbols are handled between the parser
and object format.  Instead of creating special symbols with the right
names, instead have the parser call the object format to see if a match
is found into the special symbols, which are no longer stored in the
symbol table.

svn path=/trunk/yasm/; revision=2035
2008-02-09 03:35:07 +00:00
Peter Johnson
02075ed7ca Fix #123: Be explicit that errors are such by printing "error:" at beginning
of error messages.

svn path=/trunk/yasm/; revision=2019
2007-12-04 06:19:07 +00:00
Peter Johnson
52affeb01a Add NASM-compatible multi-section binary support to bin object format.
This allows for arbitrary load (LMA) and execution (VMA) addresses.

The following new section attributes are supported:
 - start (LMA start address)
 - follows (follow another section's last LMA)
 - align (LMA alignment)
 - vstart (VMA start address)
 - vfollows (follow another section's last VMA)
 - valign (VMA alignment)
In addition, sections can be designed progbits or nobits.

The following special symbols are generated for program use:
 - section.<sectname>.start (LMA start address)
 - section.<sectname>.vstart (VMA start address)
 - section.<sectname>.length (section length)

The ORG directive adjusts the file offset relative to LMA, so that if
ORG=0x100, a section with LMA=0x100 will be at file offset 0.

VMA addresses are the same as LMA addresses unless otherwise specified.

Full map file support is supported via the [MAP] directive.  The map output
filename can be set either as a parameter to the [MAP] directive or on the
command line with --mapfile=<filename>.  MAP options are BRIEF, SECTIONS,
SEGMENTS, SYMBOLS, and ALL (all of the above).  If no filename is specified
either on the command line or in the source file, the map is output to
standard output.

Full documentation will be added to the Yasm manual in the near future.

This implementation supports several configurations NASM does not, for
instance http://osdir.com/ml/lang.nasm.devel/2004-12/msg00032.html .
It is also fully 64-bit aware.

Fixes: #71, #99.

svn path=/trunk/yasm/; revision=2010
2007-11-14 08:33:32 +00:00
Peter Johnson
39913f32de Fix #114: Incorrect ELF32 ..gotpc address calculation.
Reported by: Loren Merritt
Fix by: mu@

We already had a testcase for this, but it had an incorrect "golden" result.

svn path=/trunk/yasm/; revision=1952
2007-09-15 06:40:27 +00:00
Peter Johnson
2bb74148c1 Merge expr-int.h into expr.h, removing YASM_EXPR_INTERNAL in the process.
svn path=/trunk/yasm/; revision=1895
2007-07-14 05:31:08 +00:00
Peter Johnson
a958ef6df8 Merge bc-int.h into bytecode.h, removing YASM_BC_INTERNAL in the process.
svn path=/trunk/yasm/; revision=1894
2007-07-14 04:34:41 +00:00
Peter Johnson
ab13bd719e Remove YASM_LIB_INTERNAL. It never really gained us that much in terms of
visibility savings, as basically everything defined it.

svn path=/trunk/yasm/; revision=1893
2007-07-14 03:11:32 +00:00
Peter Johnson
3e5fed2ad1 Clean up directive handling. This standardizes error/warning messages and
makes value/parameters more well-defined and flexible enough to handle
string parameters.  Value/parameters would now be better called name/values,
but avoid changing the name for now.

svn path=/trunk/yasm/; revision=1851
2007-05-26 17:56:36 +00:00
Peter Johnson
4bfff483e5 Move absolute section handling into NASM parser, removing all traces of it
from libyasm core.  Now absolute sections are tracked locally to the parser
and the parser generates EQUs directly for labels in absolute sections.

Fixes #106 and #103.

svn path=/trunk/yasm/; revision=1842
2007-05-15 07:27:26 +00:00
Peter Johnson
469e54fa4a Update all copyright dates.
svn path=/trunk/yasm/; revision=1827
2007-04-22 05:09:49 +00:00
Peter Johnson
00473ca981 Bite the bullet and convert tabs to spaces. Previously yasm's source has
been using a mix of tabs and 4 spaces to indent; this looks horrible if
tab size is ever not 8.  While I debated converting to tab-only indentation
that would have been a far higher impact to the source.

svn path=/trunk/yasm/; revision=1825
2007-04-22 03:32:46 +00:00
Peter Johnson
decb27eaa2 Massive update of directive handling, including handling of extern, global,
and common declare.  The latter no longer passes through objfmt at parse time;
instead the objfmt must handle them at output time (objfmt-specific
extensions are parsed & stored by the parser).  Directives are now handled
using a list (with function pointers) rather than a single function entry
point.

svn path=/trunk/yasm/; revision=1819
2007-03-21 04:23:59 +00:00
Peter Johnson
415eee49ea Restructure yasm_object as the central clearing house for yasm_objfmt,
yasm_dbgfmt, and yasm_arch.  This eliminates a lot of redundant keeping
track of this information in the individual object and debug formats and
also simplifies a fair amount of code.

I'm still not happy with how arch gets passed around in output code, but
there may not be much of an alternative there.

While I'm here, clean up some unused variables and functions and re-enable
the warning for unused variables in configure.ac.

svn path=/trunk/yasm/; revision=1812
2007-03-05 08:43:00 +00:00
Peter Johnson
37436edcb4 Fix a couple of NULL pointer derefs.
Found by: zzuf (http://sam.zoy.org/zzuf/)

svn path=/trunk/yasm/; revision=1808
2007-03-04 01:00:01 +00:00
Peter Johnson
2f2180767d Massive warnings cleanup and cleanup of size_t vs uintptr_t vs unsigned long.
svn path=/trunk/yasm/; revision=1792
2007-02-24 20:19:27 +00:00
Peter Johnson
e7b1cea7ff Allow directives to have no parameters in the parser, and check for it at
a lower level.

To reduce code duplication, refactor several of the large if/else structures
into multiple functions with a lookup table.

Add support for registers to be used in directive expressions.

Allow directives to have underscores and numbers (still cannot start with
numbers).

svn path=/trunk/yasm/; revision=1757
2007-02-07 08:29:41 +00:00
Peter Johnson
fdf47df378 Support forced identifiers ($foo) in directives. This makes yasm match
NASM behavior with regards to e.g. extern $foo.

Unfortunately this makes yasm start not matching NASM behavior with regards
to the RDF module directive.  In NASM, module $foo results in a literal $foo
reference; yasm now requires either a double $ (e.g. $$foo) or quotes (e.g.
"$foo").  The special case for section (section $foo --> literal $foo) is
still present, but keeping this for other directives is extremely difficult.

svn path=/trunk/yasm/; revision=1754
2007-02-05 08:11:52 +00:00
Peter Johnson
b188db0311 NASM parser bugfixes, and add support for section names that include "-"
(such as the common .note.GNU-stack section).  While Yasm allows such section
names by enclosing with double-quotes, NASM allows this, so for compatibility
it makes sense for Yasm to as well.

svn path=/trunk/yasm/; revision=1723
2006-12-30 02:48:17 +00:00
Peter Johnson
0b54266d14 Fix bad valparams setup introduced in previous commit. yasm_vps_append()
is a macro and does bad things when given a non-variable.

Tracked down by: Peter Tanski <p.tanski@gmail.com>

svn path=/trunk/yasm/; revision=1713
2006-12-17 18:11:00 +00:00