This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Test that invalid symbol/relocation types generate errors
ClosedPublic

Authored by sbc100 on Jan 21 2021, 12:09 PM.

Diff Detail

Event Timeline

sbc100 created this revision.Jan 21 2021, 12:09 PM
sbc100 requested review of this revision.Jan 21 2021, 12:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 21 2021, 12:09 PM
sbc100 edited the summary of this revision. (Show Details)Jan 21 2021, 12:11 PM
sbc100 added a reviewer: dschuff.
dschuff accepted this revision.Jan 21 2021, 1:23 PM

IIUC this doesn't prevent the crash in lld, it just improves the error message when reading the object file?

This revision is now accepted and ready to land.Jan 21 2021, 1:23 PM

Yes, it turns out that the crash in LLD was a special case of llvm being aware of a new symbol type but lld not being testing with it.. in practice that should be rare. It was bad luck that it bit us I think,

This revision was landed with ongoing or failed builds.Jan 21 2021, 2:02 PM
This revision was automatically updated to reflect the committed changes.

In ELF, we usually use yaml2obj to generate invalid object files, instead of checking in precanned binaries. You can find lots of grimar's changes migrating away from binaries.

In ELF, we usually use yaml2obj to generate invalid object files, instead of checking in precanned binaries. You can find lots of grimar's changes migrating away from binaries.

I generally prefer that method too, however I didn't think it was possible for this kind of case. How would I generate an invalid relocation type? Currently relocations are specified with a string:

For example here is the yaml I used as a starting point for this invalid binary:

--- !WASM
FileHeader:
  Version:         0x1
Sections:
  - Type:            TYPE
    Signatures:
      - Index:           0
        ParamTypes:      []
        ReturnTypes:
          - I32
  - Type:            FUNCTION
    FunctionTypes:   [ 0 ]
  - Type:            CODE
    Relocations:
      - Type:            R_WASM_TABLE_INDEX_SLEB
        Index:           0
        Offset:          0x4
    Functions:
      - Index:           0
        Locals:          []
        Body:            4181808080000B
  - Type:            CUSTOM
    Name:            linking
    Version:         2
    SymbolTable:
      - Index:           0
        Kind:            FUNCTION
        Name:            foo
        Flags:           [ VISIBILITY_HIDDEN ]
        Function:        0

In this case I modified the binary to change the R_WASM_TABLE_INDEX_SLEB value to 63 (an invalid value). If I try to do that in the yaml I get:

yaml2obj out.yaml > obj.o
YAML:15:26: error: unknown enumerated scalar
      - Type:            63
                         ^~
yaml2obj: error: failed to parse YAML input: Invalid argument

Also, I see a lot of ELF files (and very few yaml files) checked in directly to llvm/test/Object/Inputs/. Is that just because there is ongoing work to covert them?

In ELF, we usually use yaml2obj to generate invalid object files, instead of checking in precanned binaries. You can find lots of grimar's changes migrating away from binaries.

I generally prefer that method too, however I didn't think it was possible for this kind of case. How would I generate an invalid relocation type? Currently relocations are specified with a string:

For example here is the yaml I used as a starting point for this invalid binary:

--- !WASM
FileHeader:
  Version:         0x1
Sections:
  - Type:            TYPE
    Signatures:
      - Index:           0
        ParamTypes:      []
        ReturnTypes:
          - I32
  - Type:            FUNCTION
    FunctionTypes:   [ 0 ]
  - Type:            CODE
    Relocations:
      - Type:            R_WASM_TABLE_INDEX_SLEB
        Index:           0
        Offset:          0x4
    Functions:
      - Index:           0
        Locals:          []
        Body:            4181808080000B
  - Type:            CUSTOM
    Name:            linking
    Version:         2
    SymbolTable:
      - Index:           0
        Kind:            FUNCTION
        Name:            foo
        Flags:           [ VISIBILITY_HIDDEN ]
        Function:        0

In this case I modified the binary to change the R_WASM_TABLE_INDEX_SLEB value to 63 (an invalid value). If I try to do that in the yaml I get:

yaml2obj out.yaml > obj.o
YAML:15:26: error: unknown enumerated scalar
      - Type:            63
                         ^~
yaml2obj: error: failed to parse YAML input: Invalid argument

Also, I see a lot of ELF files (and very few yaml files) checked in directly to llvm/test/Object/Inputs/. Is that just because there is ongoing work to covert them?

Maybe D95661:)