| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Some segments, like the 'vectors' one, will reference code that is
outside of its mapping. But in some other configurations, segments
cannot make these cross-mapping references so happily. Imagine:
.segment "SWAPPABLE"
.proc foo
rts
.endproc
.segment "FIXED"
jsr foo
Here the assembler will properly detect the address of 'foo' in the
context of the 'SWAPPABLE' segment. But what this assembler doesn't know
is that this segment is swappable (e.g. UNROM chip). Hence, if the bank
being mapped right now is not the one containing the 'SWAPPABLE'
segment, then the address computed for 'foo' and used in that 'jsr'
instruction will point to something else entirely. This would be similar
to a use-after-free bug.
This is something that can only be inspected at runtime, and so the
assembler cannot be of much help here. Hence, this commit adds a warning
so the programmer can understand the potentially dangerous operation.
All of that being said, this commit also adds support for "asan:safe" or
"check:safe", which is a magic comment that the programmer can write to
re-assure the assembler that this operation is fine (e.g. there is a
guarantee that the mapped bank is that one we are expecting). Hence, the
code above could now be written like so:
jsr foo ; check:safe
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
The enum type for macro arguments has been adjusted so it accepts a
String. This is then used to store the name of the macro for this
argument.
This is a bit of a circlejerk, but in the end it stems from the fact
that macro arguments were sort of a hack defined ad-hoc each time they
were needed. That being said, if we want to report macro arguments being
unused, we need to reference the actual macro definition, not the macro
call.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
|
|
|
|
| |
It was downright lazy from my end to not inspect the line of the object
that was being unused. Fix this by trying to fetch the bundle's node.
This right now applies to variable definitions. Objects like macro
arguments are pending to be done.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Macro arguments get tampered with every time a new call has to be
bundled. Deep down this is done by cloning the underlying object, but
this resets any increase on the 'accessed' member, giving always the
impression that macro arguments are never accessed. Fix this by at least
preserving this member when cloning a macro argument.
Note that this is neither the most elegant solution, and probably not
the most correct. As in, it will probably get into a non-precise count
after some calls. But at least it will be a non-zero value, which is
more than enough to what this is actually used for.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When warning users on unused objects (e.g. variables, proc's), we have
to pick up the source of origin for this warning. In places where the
original PNode is not available, then we go with the last source we have
at hand, as that's the usual way to go (i.e. the error occurred at the
current source/context).
That being said, for unused objects that's not desirable, because we
might otherwise claim the error to happen on the file we first
targetted, but it's way more useful to understand where the object was
defined.
Hence, when defining a variable, address or proc, let's actually store
the PNode associated with it as well. This way the checker can hopefully
get the source from this PNode and be more clear to the user.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
| |
Fixes 4f1a9c660108 ("Add the .fallthrough control statement")
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Bundle call arguments were fine most of the times, when arguments could
be processed as-is and there were no issues with arguments being
overwritten by successive calls.
This was not the case, though, whenever a given instruction was delayed
into a PendingNode status. In this case, the argument would get the
last value, and in some extreme cases that definition might not have
been there any more.
Prevent all of this by providing a list of PendingDefine's, which are a
way to re-create these call-only arguments as they were initially
found. These PendingDefine's are then created on "crunch" on each
PendingNode.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
|
| |
They should be expanded to a 16-bit address from the zero-page. The fact
that the assembler was complaining about it was simply erroneous.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
There were two bugs involved at the same time. First, for some reason,
the "matches" clause was negated, which defeats the purpose of the
check. This even resulted in a bad test run which was accepted because I
just did not caught it before.
Second, pure indirect addressing mode is only available for the "jmp"
instruction. Hence, there's no need for that "matches" at all, and even
less to filter that based on "jsr" which doesn't even implement this
addressing mode.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
|
| |
This was already the case for plain addresses, but it was not being
considered in the case of an arithmetic operation.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
|
| |
Add the target and effective addresses into the message, so it's more
clear how different they are.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
|
|
| |
This was apparently neglected and you were able to pick invalid
identifiers to identify procs, macros and scopes. Ensure this does not
happen again and provide tests for it.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This is exclusive to 'nasm' and it allows the developer to explicitly
tell the assembler than a "fall through" condition is actually desired:
it's not a mistake.
This comes in two flavors. The first, without arguments, just makes this
explicit without much enforcement. The second allows you to pass an
argument which is the name of the function or label you are expecting to
fall through. The assembler will error out if the fall through address
is not the expected one, hence telling the programmer whenever the fall
through condition they thought in the past is no longer true (e.g. the
function has moved somewhere else in the code).
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Sometimes performing some 'jmp'/'jsr' can be quite pointless, and the
programmer might not be fully aware of this because of the layout of the
code. Imagine:
.proc foo
;; code
jmp bar
.endproc
;; Documentation, comments, extra space, etc.
.proc bar
;; whatever
.endproc
The 'jmp' in the code above tries to perform a call stack optimization,
but it's actually not needed because the next instruction after 'jmp' is
the one inside of 'bar', but that's obfuscated because of the layout.
In these sort of cases (and also for 'jsr' and branches) warn the
programmer about it so it can remove that instruction.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This way, if you define a constant like:
MY_BUFFER_LEN_IN_BYTES = $10
You can then declare your buffer like so:
zp_buffer = $00 ; asan:reserve MY_BUFFER_LEN_IN_BYTES
And then further in the code you can rely on just using the constant for
bound checking, and then the address sanitizer will check on bound
checks via static analysis as well.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
|
| |
|
|
|
|
| |
The check was not being applied on certain conditions.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
This check ensures that asan-friendly names actually match their
expected scope.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
The address sanitizer is now able to detect whenever in an instruction a
memory access is done without using variables. This is now detected for
all instructions except for branching, which falls outside of this
scope.
Moreover, simple arithmetics is allowed and bounds are checked for
simple cases. That being said, more involved bound checks should be done
with other tools (e.g. emulators).
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
|
|
This allows users to define variables directly from the command line,
which is useful for testing purposes.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|