Skip to content
This repository has been archived by the owner on Jan 9, 2021. It is now read-only.

MetadataReader does not work on ARM #64

Closed
wfurt opened this issue Jul 20, 2018 · 1 comment
Closed

MetadataReader does not work on ARM #64

wfurt opened this issue Jul 20, 2018 · 1 comment

Comments

@wfurt
Copy link
Member

wfurt commented Jul 20, 2018

I was trying to build corefx on Linux arm:

  Unhandled Exception: System.DataMisalignedException: A datatype misalignment was detected in a load or store instruction.
     at Microsoft.Cci.MetadataReader.PEFileToObjectModel.GetDefaultValue(MetadataObject metadataObject)
     at Microsoft.Cci.MetadataReader.ObjectModelImplementation.FieldDefinition.get_CompileTimeValue()
     at Microsoft.Cci.MutableCodeModel.FieldDefinition.Copy(IFieldDefinition fieldDefinition, IInternFactory internFactory)
     at Microsoft.Cci.MutableCodeModel.MetadataShallowCopier.CopyUnspecialized(IFieldDefinition fieldDefinition)
     at Microsoft.Cci.MutableCodeModel.MetadataShallowCopier.MetadataDispatcher.Visit(IFieldDefinition fieldDefinition)
     at Microsoft.Cci.MetadataReader.ObjectModelImplementation.FieldDefinition.Dispatch(IMetadataVisitor visitor)
     at Microsoft.Cci.MutableCodeModel.MetadataShallowCopier.Copy(IFieldDefinition fieldDefinition)
     at Microsoft.Cci.MutableCodeModel.MetadataDeepCopier.Populator.Visit(IFieldDefinition fieldDefinition)
     at Microsoft.Cci.MetadataReader.ObjectModelImplementation.FieldDefinition.Dispatch(IMetadataVisitor visitor)
     at Microsoft.Cci.MetadataTraverser.Traverse(IFieldDefinition fieldDefinition)
     at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 fields)
     at Microsoft.Cci.MetadataTraverser.TraverseChildren(ITypeDefinition typeDefinition)
     at Microsoft.Cci.MetadataTraverser.TraverseChildren(INamedTypeDefinition namedTypeDefinition)
     at Microsoft.Cci.MetadataTraverser.TraverseChildren(INamespaceTypeDefinition namespaceTypeDefinition)
     at Microsoft.Cci.MetadataTraverser.Traverse(INamespaceTypeDefinition namespaceTypeDefinition)
     at Microsoft.Cci.MetadataTraverser.Dispatcher.Visit(INamespaceTypeDefinition namespaceTypeDefinition)
     at Microsoft.Cci.MetadataReader.ObjectModelImplementation.NamespaceType.Dispatch(IMetadataVisitor visitor)
     at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 namespaceMembers)
     at Microsoft.Cci.MetadataTraverser.TraverseChildren(INamespaceDefinition namespaceDefinition)
     at Microsoft.Cci.MetadataTraverser.TraverseChildren(IUnitNamespace namespaceDefinition)
     at Microsoft.Cci.MetadataTraverser.TraverseChildren(INestedUnitNamespace nestedUnitNamespace)
     at Microsoft.Cci.MetadataTraverser.Traverse(INestedUnitNamespace nestedUnitNamespace)
     at Microsoft.Cci.MetadataTraverser.Dispatcher.Visit(INestedUnitNamespace nestedUnitNamespace)
     at Microsoft.Cci.MetadataReader.ObjectModelImplementation.NestedNamespace.Dispatch(IMetadataVisitor visitor)
     at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable`1 namespaceMembers)
     at Microsoft.Cci.MetadataTraverser.TraverseChildren(INamespaceDefinition namespaceDefinition)
     at Microsoft.Cci.MetadataTraverser.TraverseChildren(IUnitNamespace namespaceDefinition)
     at Microsoft.Cci.MetadataTraverser.TraverseChildren(IRootUnitNamespace rootUnitNamespace)
     at Microsoft.Cci.MetadataTraverser.Traverse(IRootUnitNamespace rootUnitNamespace)
     at Microsoft.Cci.MetadataTraverser.TraverseChildren(IModule module)
     at Microsoft.Cci.MetadataTraverser.TraverseChildren(IAssembly assembly)
     at Microsoft.Cci.MetadataTraverser.Traverse(IAssembly assembly)
     at Microsoft.Cci.MutableCodeModel.MetadataDeepCopier.Copy(IAssembly assembly)
     at GenFacades.Generator.Execute(String seeds, String contracts, String facadePath, Version assemblyFileVersion, Boolean clearBuildAndRevision, Boolean ignoreMissingTypes, Boolean ignoreBuildAndRevisionMismatch, Boolean buildDesignTimeFacades, String inclusionContracts, ErrorTreatment seedLoadErrorTreatment, ErrorTreatment contractLoadErrorTreatment, String[] seedTypePreferencesUnsplit, Boolean forceZeroVersionSeeds, Boolean producePdb, String partialFacadeAssemblyPath, Boolean buildPartialReferenceFacade)
     at GenFacades.Program.Main(String[] args)
  Aborted (core dumped)
/home/pi/github/wfurt-corefx2/src/shims/shims.proj(56,5): error MSB3073: The command ""/home/pi/github/wfurt-corefx2/Tools/dotnetcli/dotnet" "/home/pi/github/wfurt-corefx2/Tools/GenFacades.exe" -contracts:"/home/pi/github/wfurt-corefx2/bin/ref/netfx/mscorlib.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Configuration.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Core.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Data.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Drawing.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.IO.Compression.FileSystem.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Net.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Numerics.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Runtime.Serialization.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Security.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.ServiceProcess.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Transactions.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Web.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Windows.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Xml.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Xml.Serialization.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Xml.Linq.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.ComponentModel.DataAnnotations.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.ServiceModel.Web.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/WindowsBase.dll" @"/home/pi/github/wfurt-corefx2/bin/obj/shims/netcoreapp/genfacades.rsp"" exited with code 134.

Build FAILED.

/home/pi/github/wfurt-corefx2/src/shims/shims.proj(56,5): error MSB3073: The command ""/home/pi/github/wfurt-corefx2/Tools/dotnetcli/dotnet" "/home/pi/github/wfurt-corefx2/Tools/GenFacades.exe" -contracts:"/home/pi/github/wfurt-corefx2/bin/ref/netfx/mscorlib.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Configuration.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Core.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Data.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Drawing.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.IO.Compression.FileSystem.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Net.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Numerics.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Runtime.Serialization.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Security.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.ServiceProcess.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Transactions.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Web.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Windows.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Xml.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Xml.Serialization.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.Xml.Linq.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.ComponentModel.DataAnnotations.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/System.ServiceModel.Web.dll;/home/pi/github/wfurt-corefx2/bin/ref/netfx/WindowsBase.dll" @"/home/pi/github/wfurt-corefx2/bin/obj/shims/netcoreapp/genfacades.rsp"" exited with code 134.
    0 Warning(s)
    1 Error(s)

It seems like the correct code may be already there under #if COMPACTFX
However, there is no provision to enable that for ARM. Also the package targets ANY_CPU.
So it is really not sure up right now to provide multi-architecture support.
One option would be changing the compile-time checks to runtime option.

PEReaderAndWriter/PEReader/UnmanagedReadWrite.c:

nternal UInt32 PeekUInt32(
      uint offset
    ) {
#if COMPACTFX
      if ((int)(this.CurrentPointer + offset) % 4 != 0) return UnalignedPeekUInt32(offset);
#endif
      if (checked(this.CurrentPointer - this.Buffer + offset + sizeof(UInt32)) > this.Length)
        throw new ArgumentOutOfRangeException();
#if LITTLEENDIAN
      return *(UInt32*)(this.CurrentPointer + offset);
#elif BIGENDIAN
      uint uin = *(uint*)(this.CurrentPointer + offset);
      uin = (uin >> 16) | (uin << 16);
      uin = ((uin & 0xFF00FF00) >> 8) | ((uin & 0x00FF00FF) << 8);
      return uin;
#endif
    }

cc: @nguerrera @ericstj

@wfurt
Copy link
Member Author

wfurt commented Jul 20, 2018

one more note that the ((int)(this.CurrentPointer + offset) % 4 != 0) will not work properly on arm64 as it needs to align on 8 byte boundary.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants