#111 '-' in .c filename

closed-fixed
nobody
5
2013-05-25
2001-08-18
Anonymous
No

If you want to compile a filename that matches
*-*.c (i.e.: the filename contains a '-'), it
won't compile.
Example:

int c, s, i, l;
int main() {
while (1) {
c = sizeof(char);
s = sizeof(short);
i = sizeof(int);
l = sizeof(long);
}
}

if you name it test-sdcc.c it won't compile, but it
will if you name it test.c

Discussion

  • Johan Knol
    Johan Knol
    2001-08-19

    Logged In: YES
    user_id=63512

    I don't see this on Linux. What platform are you using?

     
  • Logged In: NO

    I am currently using red-hat 6.1 (Cartman).
    Here's what I try:
    $ sdcc asdf.c

    library file /usr/local/share/lib/small/libsdcc.lib
    library file /usr/local/share/lib/small/libint.lib
    library file /usr/local/share/lib/small/liblong.lib
    library file /usr/local/share/lib/small/libfloat.lib
    $ cp asdf.c asdf-asdf.c
    $ sdcc asdf-asdf.c
    ?ASxxxx-Error-<o> in line 141 of asdf-asdf.asm
    <o> .org in REL area or directive / mnemonic
    error

    library file /usr/local/share/lib/small/libsdcc.lib
    library file /usr/local/share/lib/small/libint.lib
    library file /usr/local/share/lib/small/liblong.lib
    library file /usr/local/share/lib/small/libfloat.lib
    Invalid symbol type - for A$asdf

     
  • Logged In: YES
    user_id=104682

    Opps... I really should have posted this as a comment on
    the bug tracking, instead of to the mail list... here
    goes:

    >> if you name it test-sdcc.c it won't compile, but it
    >> will if you name it test.c
    >
    >I don't see this on Linux. Anyone? Anywhere?

    Yep, I was able to reproduce it, using a sdcc compiled from
    a cvs update last night, running on linux (redhat 7.1).

    You will NOT see the bug is you compile with -c, as the
    linker is what is complaining.

    It looks like the linker is unhappy about lines like:

    S A$test-sdcc$109 Def0038
    S A$test-sdcc$50 Def0000
    S A$test-sdcc$51 Def0003

    in the .rel file. As nearly as I can tell, newsym in
    as/mcs51/lksym.c is called the parse these lines if the
    main program finds the first character to be 'S', and
    the first thing it does is call getid (in lklex.c),
    which doesn't allow '-' in symbol names.

    Digging just a bit deeper, it looks like the linker uses
    a char ctype[128] table lookup to figure out what type
    of character each ascii byte is, and getid will stop
    parsing the symbol when it sees any character that is
    not LETTER and DIGIT (DIGIT includes DGT2, DGT8, DGT10).

    char ctype[128] = {
    /*NUL*/ ILL, ILL, ILL, ILL, ILL, ILL,
    ILL, ILL,
    /*BS*/ ILL, SPACE, ILL, ILL, SPACE, ILL,
    ILL, ILL,
    /*DLE*/ ILL, ILL, ILL, ILL, ILL, ILL,
    ILL, ILL,
    /*CAN*/ ILL, ILL, ILL, ILL, ILL, ILL,
    ILL, ILL,
    /*SPC*/ SPACE, ETC, ETC, ETC, LETTER, BINOP,
    BINOP, ETC,
    /*(*/ ETC, ETC, BINOP, BINOP, ETC, BINOP,
    LETTER, BINOP,
    /*0*/ DGT2, DGT2, DGT8, DGT8, DGT8, DGT8,
    DGT8, DGT8,
    /*8*/ DGT10, DGT10, ETC, ETC, BINOP, ETC,
    BINOP, ETC,
    /*@*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16,
    LTR16, LETTER,
    /*H*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
    LETTER, LETTER,
    /*P*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
    LETTER, LETTER,
    /*X*/ LETTER, LETTER, LETTER, ETC, ETC, ETC,
    BINOP, LETTER,
    /*`*/ ETC, LTR16, LTR16, LTR16, LTR16, LTR16,
    LTR16, LETTER,
    /*h*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
    LETTER, LETTER,
    /*p*/ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
    LETTER, LETTER,
    /*x*/ LETTER, LETTER, LETTER, ETC, BINOP, ETC,
    ETC, ETC
    };

    The '$' is marked as LETTER (5th row, 5th column). '-' is
    marked as BINOP (6th row, 6th column), so getid stops
    parsing
    the symbol name, and the newsym expects to find either a
    'D' or 'R' ("Def" or "Ref", though it ignores the other two
    characters). When it finds the '-' that SDCC copied into
    the
    symbol name from the filename, the user ends up with:

    Invalid symbol type - for A$test

    When I started digging, I thought I'd figure out what was
    wrong and fix it. Honestly, I'm a bit scared to touch the
    linker now... especially turning BINOP into LETTER in a
    table like that!

    The underscore is marked as letter, so I think it would be
    best if SDCC were to turn any character that isn't A-Z,
    a-z,
    0-9 or underscore into an underscore when it creates global
    symbol names that include a filename.

    Saddly, I haven't (yet) learned much about how the
    higher-level
    parts of SDCC work, so it's better if someone did this.

    Paul

     
  • Bernhard Held
    Bernhard Held
    2001-08-30

    Logged In: YES
    user_id=203539

    Fixed in the linker.

     
  • Johan Knol
    Johan Knol
    2001-09-07

    Logged In: YES
    user_id=63512

    Please remove the bug report after fixing :)

     
  • Johan Knol
    Johan Knol
    2001-09-07

    • milestone: --> fixed
    • status: open --> closed-fixed