[nasm:nasm-2.16.xx] BR 3392571: allow the user to request warnings for relocations

nasm-bot for H. Peter Anvin hpa at zytor.com
Wed Oct 11 12:39:04 PDT 2023


Commit-ID:  e64ae0a0c68edccf544c915a6cc65a562f1629b4
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=e64ae0a0c68edccf544c915a6cc65a562f1629b4
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Wed, 11 Oct 2023 12:34:52 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Wed, 11 Oct 2023 12:34:52 -0700

BR 3392571: allow the user to request warnings for relocations

Some target environments may have specific restrictions on what kinds
of relocations are possible or allowed. Allow users to opt-in to
specific warnings as to the relocations they cannot support.

Requested-by: C. Masloch <pushbx at ulukai.org>
Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 asm/assemble.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 117 insertions(+), 12 deletions(-)

diff --git a/asm/assemble.c b/asm/assemble.c
index 7eab5ce1..8bdc221e 100644
--- a/asm/assemble.c
+++ b/asm/assemble.c
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------- *
  *
- *   Copyright 1996-2022 The NASM Authors - All Rights Reserved
+ *   Copyright 1996-2023 The NASM Authors - All Rights Reserved
  *   See the file AUTHORS included with the NASM distribution for
  *   the specific copyright holders.
  *
@@ -385,18 +385,123 @@ static void out(struct out_data *data)
         nasm_assert(data->size <= 8);
         asize = data->size;
         amax = ofmt->maxbits >> 3; /* Maximum address size in bytes */
-        if (!(ofmt->flags & OFMT_KEEP_ADDR) &&
-            data->tsegment == fixseg &&
-            data->twrt == NO_SEG) {
-            if (asize >= (size_t)(data->bits >> 3)) {
-                 /* Support address space wrapping for low-bit modes */
-                data->flags &= ~OUT_SIGNMASK;
+        if (data->tsegment == fixseg && data->twrt == NO_SEG) {
+            if (!(ofmt->flags & OFMT_KEEP_ADDR)) {
+                if (asize >= (size_t)(data->bits >> 3)) {
+                    /* Support address space wrapping for low-bit modes */
+                    data->flags &= ~OUT_SIGNMASK;
+                }
+                warn_overflow_out(addrval, asize, data->flags);
+                xdata.q = cpu_to_le64(addrval);
+                data->data = xdata.b;
+                data->type = OUT_RAWDATA;
+                asize = amax = 0;   /* No longer an address */
+            }
+        } else {
+            /*!
+             *!reloc-abs-byte [off] 8-bit absolute section-crossing relocation
+             *!  warns that an 8-bit absolute relocation that could
+             *!  not be resolved at assembly time was generated in
+             *!  the output format.
+             *!
+             *!  This usually normal, but may not be handled by all
+             *!  possible target environments
+             */
+            /*!
+             *!reloc-abs-word [off] 16-bit absolute section-crossing relocation
+             *!  warns that a 16-bit absolute relocation that could
+             *!  not be resolved at assembly time was generated in
+             *!  the output format.
+             *!
+             *!  This usually normal, but may not be handled by all
+             *!  possible target environments
+             */
+            /*!
+             *!reloc-abs-dword [off] 32-bit absolute section-crossing relocation
+             *!  warns that a 32-bit absolute relocation that could
+             *!  not be resolved at assembly time was generated in
+             *!  the output format.
+             *!
+             *!  This usually normal, but may not be handled by all
+             *!  possible target environments
+             */
+            /*!
+             *!reloc-abs-qword [off] 64-bit absolute section-crossing relocation
+             *!  warns that a 64-bit absolute relocation that could
+             *!  not be resolved at assembly time was generated in
+             *!  the output format.
+             *!
+             *!  This usually normal, but may not be handled by all
+             *!  possible target environments
+             */
+            /*!
+             *!reloc-rel-byte [off] 8-bit relative section-crossing relocation
+             *!  warns that an 8-bit relative relocation that could
+             *!  not be resolved at assembly time was generated in
+             *!  the output format.
+             *!
+             *!  This usually normal, but may not be handled by all
+             *!  possible target environments
+             */
+            /*!
+             *!reloc-rel-word [off] 16-bit relative section-crossing relocation
+             *!  warns that a 16-bit relative relocation that could
+             *!  not be resolved at assembly time was generated in
+             *!  the output format.
+             *!
+             *!  This usually normal, but may not be handled by all
+             *!  possible target environments
+             */
+            /*!
+             *!reloc-rel-dword [off] 32-bit relative section-crossing relocation
+             *!  warns that a 32-bit relative relocation that could
+             *!  not be resolved at assembly time was generated in
+             *!  the output format.
+             *!
+             *!  This usually normal, but may not be handled by all
+             *!  possible target environments
+             */
+            /*!
+             *!reloc-rel-qword [off] 64-bit relative section-crossing relocation
+             *!  warns that an 64-bit relative relocation that could
+             *!  not be resolved at assembly time was generated in
+             *!  the output format.
+             *!
+             *!  This usually normal, but may not be handled by all
+             *!  possible target environments
+             */
+            int warn;
+            const char *type;
+
+            switch (data->type) {
+            case OUT_ADDRESS:
+                type = "absolute";
+                switch (asize) {
+                case 1: warn = WARN_RELOC_ABS_BYTE; break;
+                case 2: warn = WARN_RELOC_ABS_WORD; break;
+                case 4: warn = WARN_RELOC_ABS_DWORD; break;
+                case 8: warn = WARN_RELOC_ABS_QWORD; break;
+                default: panic();
+                }
+                break;
+            case OUT_RELADDR:
+                type = "relative";
+                switch (asize) {
+                case 1: warn = WARN_RELOC_REL_BYTE; break;
+                case 2: warn = WARN_RELOC_REL_WORD; break;
+                case 4: warn = WARN_RELOC_REL_DWORD; break;
+                case 8: warn = WARN_RELOC_REL_QWORD; break;
+                default: panic();
+                }
+                break;
+            default:
+                warn = 0;
+            }
+
+            if (warn) {
+                nasm_warn(warn, "%u-bit %s section-crossing relocation",
+                          (unsigned int)(asize << 3), type);
             }
-            warn_overflow_out(addrval, asize, data->flags);
-            xdata.q = cpu_to_le64(addrval);
-            data->data = xdata.b;
-            data->type = OUT_RAWDATA;
-            asize = amax = 0;   /* No longer an address */
         }
         break;
 


More information about the Nasm-commits mailing list