[LLVMdev] [lld] Verifying the Architecture of files read

Michael Spencer bigcheesegs at gmail.com
Mon Oct 7 15:13:06 PDT 2013


On Sun, Oct 6, 2013 at 7:38 PM, Shankar Easwaran <shankare at codeaurora.org>wrote:

> On 10/4/2013 11:16 PM, Michael Spencer wrote:
>
>> On Fri, Oct 4, 2013 at 8:50 PM, Shankar Easwaran <shankare at codeaurora.org
>> >**wrote:
>>
>>  Hi,
>>>
>>> It is needed that lld verifies the input to the linker.
>>>
>>> For example : a x86 ELF file can be given to lld when the target is
>>> x86_64. Similiarly with other flavors.
>>>
>>> I was thinking to have a varargs function in the LinkingContext that
>>> would
>>> be overridden by each of the LinkingContexts to verify files after being
>>> read.
>>>
>>> The reader would call the varargs function in the LinkingContext and
>>> raise
>>> an error if the input is not suitable with the current link mode.
>>>
>>> Thanks
>>>
>>> Shankar Easwaran
>>>
>>> --
>>> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted
>>> by the Linux Foundation
>>>
>>>
>>>  Why would it need to be varargs?
>>
> LinkingContext for ELF would require fields from the ELF header to verify
> if the file thats being read belongs to the current target architecture.
>
> I am not sure of how many fields would determine the same for Darwin and
> COFF.
>
> This is the reason I thought it should be varargs.


The reader has an {ELF,COFF,Darwin}LinkingContext. It can just ask the
context.


>
>  Also, parse can just return an error that
>> specifies the format is wrong.
>>
> It would still need to call the LinkingContext to figure out if the format
> is associated with the target.


Exactly.


>
>  Specifically this would be a good place to use the user data part of
>> ErrorOr to specify what was expected and what was received.
>>
> Couldnt follow this. Can you elaborate ?


ErrorOr supports user data. See unittests/Support/ErrorOrTest.cpp.

It would simply be: return ArchMismatch(expected, actual);

Then an error handler higher up can extract that to form a proper error
message.

- Michael Spencer


>
>
> Thanks
>
> Shankar Easwaran
>
> --
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted
> by the Linux Foundation
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131007/8e20737e/attachment.html>


More information about the llvm-dev mailing list