bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/24411] New: Division is not accepted in MEMORY length expression


From: rda_emcraft at mail dot ru
Subject: [Bug ld/24411] New: Division is not accepted in MEMORY length expression
Date: Tue, 02 Apr 2019 15:45:49 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=24411

            Bug ID: 24411
           Summary: Division is not accepted in MEMORY length expression
           Product: binutils
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: rda_emcraft at mail dot ru
  Target Milestone: ---

I've encountered that division is not accepted in the expression specifying
length of a memory region.

I was able to confirm that at least the following versions of ld are affected:

(Fedora29-x64)
GNU ld version 2.31.1-24.fc29
Copyright (C) 2018 Free Software Foundation, Inc.

(slackware-x64)
GNU ld version 2.26.20160125
Copyright (C) 2015 Free Software Foundation, Inc.

(arm-none-eabi)
GNU ld (GNU Tools for Arm Embedded Processors 8-2018-q4-major) 2.31.51.20181213
Copyright (C) 2018 Free Software Foundation, Inc.

(arm-none-eabi)
GNU ld (Sourcery G++ Lite 2010q1-188) 2.19.51.20090709
Copyright 2008 Free Software Foundation, Inc.


The symptom is:
$cat bad.lds
MEMORY
{
    DEFAULT (r) : ORIGIN = 0x80000000, LENGTH = 0x80000000
    ROM (rx) : ORIGIN = 0, LENGTH = ((2*1024*1024)/2) + 0x1000 
    RAM (rwx) : ORIGIN = 0x20000000, LENGTH = (192*1024)
}
SECTIONS
{
    .text : {
        *(.text .stub)
        *(.glue_7t) *(.glue_7)
    } > ROM
}

$ld -T bad.lds
ld:bad.lds:4: syntax error


Replacing "/2" with ">>1" in expression remove the syntax error message:

$cat good.lds
MEMORY
{
    DEFAULT (r) : ORIGIN = 0x80000000, LENGTH = 0x80000000
    ROM (rx) : ORIGIN = 0, LENGTH = ((2*1024*1024) >> 1) + 0x1000 
    RAM (rwx) : ORIGIN = 0x20000000, LENGTH = (192*1024)
}
SECTIONS
{
    .text : {
        *(.text .stub)
        *(.glue_7t) *(.glue_7)
    } > ROM
}

$ld -T good.lds
ld: no input files

Indeed, no files were provided, but at least script is parsed successfully.

>From the ld manual:

   The ORIGIN is an numerical expression for the start address of the
memory region.  The expression must evaluate to a constant and it cannot
involve any symbols.  The keyword 'ORIGIN' may be abbreviated to 'org'
or 'o' (but not, for example, 'ORG').

  The LEN is an expression for the size in bytes of the memory region.
As with the ORIGIN expression, the expression must be numerical only and
must evaluate to a constant.  The keyword 'LENGTH' may be abbreviated to
'len' or 'l'.

So, "/2" shall be accepted. And in real world that expression comes from
expansion of preprocessor macros, so changing it is non-trivial.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]