{"id":327255,"date":"2022-01-10T08:49:18","date_gmt":"2022-01-10T08:49:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=327255"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=327255","title":{"rendered":"<span>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 ELF \u0438\u0437 \u0425\u0430\u0441\u043a\u0435\u043b\u0430<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\" class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 ELF &#8212; \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0442\u0435\u043c\u0430 \u043d\u0430 \u0425\u0430\u0431\u0440\u0435.  (<a href=\"https:\/\/habr.com\/ru\/post\/480642\/\">&#171;\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 ELF-\u0444\u0430\u0439\u043b\u044b \u0432 Linux: \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437&#187;<\/a>, <a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/583576\/\">&#171;\u041c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0430\u0439\u043b\u0430 ELF \u2013 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432 2021?&#187;<\/a> \u0438 \u0442. \u0434.)<\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0425\u0430\u0441\u043a\u0435\u043b\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u044d\u0442\u0438\u043c\u0438 \u0444\u0430\u0439\u043b\u0430\u043c\u0438: <code>elf<\/code><br \/> (<a href=\"https:\/\/hackage.haskell.org\/package\/elf\">Hackage<\/a>) \u0438 <code>data-elf<\/code> (<a href=\"https:\/\/hackage.haskell.org\/package\/data-elf\">Hackage<\/a>).  \u042d\u0442\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438 \u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u043d\u0435 \u0434\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0439 \u0444\u0430\u0439\u043b.<\/p>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <code>melf<\/code> (<a href=\"https:\/\/github.com\/aleksey-makarov\/melf\">GitHub<\/a>, <a href=\"https:\/\/hackage.haskell.org\/package\/melf\">Hackage<\/a>) \u0434\u0430\u0451\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0444\u0430\u0439\u043b ELF \u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0444\u0430\u0439\u043b \u043f\u043e \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.  \u041d\u0438\u0436\u0435 \u0434\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0435\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<h3>\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e ELF<\/h3>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 ELF \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u044b \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0444\u0430\u0439\u043b\u0430, \u0441\u0435\u043a\u0446\u0438\u0438, \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u044b, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0435\u043a\u0446\u0438\u0439, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432.  \u0421\u0435\u0433\u043c\u0435\u043d\u0442\u044b \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u043a\u043e\u043c\u043f\u0430\u043d\u043e\u0432\u0430\u043d\u044b \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u0436\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.  \u041f\u043e\u0440\u044f\u0434\u043e\u043a \u044d\u0442\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0444\u0430\u0439\u043b\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0444\u0430\u0439\u043b\u0430, \u0430 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u0435\u043a\u0446\u0438\u0439 \u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0439. \u041a\u0430\u0436\u0434\u044b\u0439 \u0442\u0430\u043a\u043e\u0439 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u0432\u044b\u0440\u043e\u0432\u043d\u0435\u043d \u0432 \u0444\u0430\u0439\u043b\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u044b \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0430 \u0441\u0435\u043a\u0446\u0438\u0438 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 &#8212; \u043d\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043b\u043e\u0432\u0430.<\/p>\n<p>\u0412 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043e, \u0433\u0434\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0435\u043a\u0446\u0438\u0439 \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442, \u0433\u0434\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u0441\u0435\u043a\u0446\u0438\u0438 \u0438 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>\u0421\u0435\u0433\u043c\u0435\u043d\u0442\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0430 \u0441\u0435\u043a\u0446\u0438\u0438 \u044f \u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b \u043a\u0430\u043a \u043d\u0435\u0434\u0435\u043b\u0438\u043c\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430.  \u0412 \u0441\u0435\u043a\u0446\u0438\u044f\u0445 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u043a\u043e\u0434, \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.  \u041b\u0438\u043d\u043a\u043e\u0432\u0449\u0438\u043a \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0441\u0435\u043a\u0446\u0438\u0438 \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438 \u0432 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>\u0412\u043f\u043e\u043b\u043d\u0435 \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0444\u0430\u0439\u043b, \u0433\u0434\u0435 \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0435 \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u043a\u0430\u043a \u043a\u0430\u043a\u0430\u044f-\u043b\u0438\u0431\u043e \u0441\u0435\u043a\u0446\u0438\u044f.<\/p>\n<h3>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c<\/h3>\n<p>\u0412 \u043c\u043e\u0434\u0443\u043b\u0435 <code>Data.Elf.Headers<\/code> <a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html\">?<\/a> \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0440\u0430\u0437\u0431\u043e\u0440 \u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0444\u0430\u0439\u043b\u0430 ELF \u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u0435\u043a\u0446\u0438\u0439 \u0438 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432.  \u0414\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u0435\u043d\u0438\u044f 64- \u0438 32-\u0431\u0438\u0442\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0442\u0438\u043f  <code>ElfClass<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:ElfClass\">?<\/a><\/p>\n<pre><code class=\"haskell\">data ElfClass     = ELFCLASS32 -- ^ 32-bit ELF format     | ELFCLASS64 -- ^ 64-bit ELF format     deriving (Eq, Show)<\/code><\/pre>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u0435\u043a\u0446\u0438\u0439 \u0438 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0437\u043d\u0443\u044e \u0448\u0438\u0440\u0438\u043d\u0443 \u0432 \u0431\u0438\u0442\u0430\u0445, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0443\u044e \u043e\u0442  <code>ElfClass<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u0435\u043d \u0442\u0438\u043f <code>WordXX a<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:WordXX\">?<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 <code>data-elf<\/code>:<\/p>\n<pre><code class=\"haskell\">-- | @IsElfClass a@ is defined for each constructor of `ElfClass`. --   It defines @WordXX a@, which is `Word32` for `ELFCLASS32` --   and `Word64` for `ELFCLASS64`. class ( SingI c       , Typeable c       , Typeable (WordXX c)       , Data (WordXX c)       , Show (WordXX c)       , Read (WordXX c)       , Eq (WordXX c)       , Ord (WordXX c)       , Bounded (WordXX c)       , Enum (WordXX c)       , Num (WordXX c)       , Integral (WordXX c)       , Real (WordXX c)       , Bits (WordXX c)       , FiniteBits (WordXX c)       , Binary (Be (WordXX c))       , Binary (Le (WordXX c))       ) => IsElfClass c where     type WordXX c = r | r -> c  instance IsElfClass 'ELFCLASS32 where     type WordXX 'ELFCLASS32 = Word32  instance IsElfClass 'ELFCLASS64 where     type WordXX 'ELFCLASS64 = Word64<\/code><\/pre>\n<p>\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0444\u0430\u0439\u043b\u0430 ELF \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0438\u043f\u0430 <code>HeaderXX a<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:HeaderXX\">?<\/a>:<\/p>\n<pre><code class=\"haskell\">-- | Parsed ELF header data HeaderXX c =     HeaderXX         { hData       :: ElfData    -- ^ Data encoding (big- or little-endian)         , hOSABI      :: ElfOSABI   -- ^ OS\/ABI identification         , hABIVersion :: Word8      -- ^ ABI version         , hType       :: ElfType    -- ^ Object file type         , hMachine    :: ElfMachine -- ^ Machine type         , hEntry      :: WordXX c   -- ^ Entry point address         , hPhOff      :: WordXX c   -- ^ Program header offset         , hShOff      :: WordXX c   -- ^ Section header offset         , hFlags      :: Word32     -- ^ Processor-specific flags         , hPhEntSize  :: Word16     -- ^ Size of program header entry         , hPhNum      :: Word16     -- ^ Number of program header entries         , hShEntSize  :: Word16     -- ^ Size of section header entry         , hShNum      :: Word16     -- ^ Number of section header entries         , hShStrNdx   :: ElfSectionIndex -- ^ Section name string table index         }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u0434\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c\u0438 \u0441 \u0440\u0430\u0437\u043d\u043e\u0439 \u0448\u0438\u0440\u0438\u043d\u043e\u0439 \u0441\u043b\u043e\u0432\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0442\u0438\u043f <code>Header<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:Header\">?<\/a>:<\/p>\n<pre><code class=\"haskell\">-- | Sigma type where `ElfClass` defines the type of `HeaderXX` type Header = Sigma ElfClass (TyCon1 HeaderXX)<\/code><\/pre>\n<p><code>Header<\/code> \u044d\u0442\u043e \u043f\u0430\u0440\u0430, \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 &#8212; \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>ElfClass<\/code>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u0448\u0438\u0440\u0438\u043d\u0443 \u0441\u043b\u043e\u0432\u0430, \u0432\u0442\u043e\u0440\u043e\u0439 &#8212; <code>HeaderXX<\/code>, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c (\u03a3-\u0442\u0438\u043f \u0438\u0437 \u044f\u0437\u044b\u043a\u043e\u0432 \u0441 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438).  \u0414\u043b\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u03a3-\u0442\u0438\u043f\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <code>singletons<\/code> (<a href=\"https:\/\/hackage.haskell.org\/package\/singletons\">Hackage<\/a>,  <a href=\"https:\/\/blog.jle.im\/entry\/introduction-to-singletons-1.html\">&#171;Introduction to singletons&#187;<\/a>).<\/p>\n<p><code>Header<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430 <code>Binary<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/binary-0.10.0.0\/docs\/Data-Binary.html#t:Binary\">?<\/a>.  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0438\u043c\u0435\u044f \u043b\u0435\u043d\u0438\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0431\u0430\u0439\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0440\u0435\u0437\u043e\u043a \u0444\u0430\u0439\u043b\u0430 ELF, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439:<\/p>\n<pre><code class=\"haskell\">withHeader ::                     BSL.ByteString ->     (forall a . IsElfClass a => HeaderXX a -> b) -> Either String b withHeader bs f =     case decodeOrFail bs of         Left (_, _, err) -> Left err         Right (_, _, (classS :&amp;: hxx) :: Header) ->             Right $ withElfClass classS f hxx<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c <code>decodeOrFail<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/binary-0.10.0.0\/docs\/Data-Binary.html#v:decodeOrFail\">?<\/a> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 <code>binary<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/binary\">?<\/a>, \u0430 <code>withElfClass<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#v:withElfClass\">?<\/a><br \/>\u0434\u0435\u043b\u0430\u0435\u0442 \u044f\u0432\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043b\u043e\u0432\u0430, \u043d\u0435\u044f\u0432\u043d\u044b\u043c (constraint).  \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 <code>withSingI<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/singletons-3.0.1\/docs\/Data-Singletons.html#v:withSingI\">?<\/a>:<\/p>\n<pre><code class=\"haskell\">-- | Convenience function for creating a -- context with an implicit ElfClass available. withElfClass :: Sing c -> (IsElfClass c => a) -> a withElfClass SELFCLASS64 x = x withElfClass SELFCLASS32 x = x<\/code><\/pre>\n<p>\u0412 <code>Data.Elf.Headers<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0442\u0430\u043a\u0436\u0435 \u0442\u0438\u043f\u044b <code>SectionXX<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:SectionXX\">?<\/a>, <code>SegmentXX<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:SegmentXX\">?<\/a> \u0438 <code>SymbolXX<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:SymbolXX\">?<\/a> \u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u0435\u043a\u0446\u0438\u0439, \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.<\/p>\n<h3>\u0412\u0435\u0440\u0445\u043d\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c<\/h3>\n<p>\u0412 \u043c\u043e\u0434\u0443\u043b\u0435 <code>Data.Elf<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf.html\">?<\/a> \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u043f\u043e\u043b\u043d\u044b\u0435 \u0440\u0430\u0437\u0431\u043e\u0440 \u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 ELF.  \u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0444\u0430\u0439\u043b \u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a ELF, \u0442\u0430\u0431\u043b\u0438\u0446a \u0441\u0435\u043a\u0446\u0438\u0439 \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u044d\u0442\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 <code>ElfXX<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf.html#t:ElfXX\">?<\/a>,  \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0449\u0438\u0439 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0444\u0430\u0439\u043b\u0430 ELF.  \u041a\u0440\u043e\u043c\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0431\u043e\u0440\u0430, \u043f\u043e \u043d\u043e\u043c\u0435\u0440\u0430\u043c \u0441\u0435\u043a\u0446\u0438\u0439 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0438\u0445 \u0438\u043c\u0435\u043d\u0430.  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>Elf<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf.html#t:Elf\">?<\/a>:<\/p>\n<pre><code class=\"haskell\">-- | `Elf` is a forrest of trees of type `ElfXX`. -- Trees are composed of `ElfXX` nodes, `ElfSegment` can contain subtrees newtype ElfList c = ElfList [ElfXX c]  -- | Elf is a sigma type where `ElfClass` defines the type of `ElfList` type Elf = Sigma ElfClass (TyCon1 ElfList)  -- | Section data may contain a string table. -- If a section contains a string table with section names, the data -- for such a section is generated and `esData` should contain `ElfSectionDataStringTable` data ElfSectionData     = ElfSectionData BSL.ByteString -- ^ Regular section data     | ElfSectionDataStringTable     -- ^ Section data will be generated from section names  -- | The type of node that defines Elf structure. data ElfXX (c :: ElfClass)     = ElfHeader         { ehData       :: ElfData    -- ^ Data encoding (big- or little-endian)         , ehOSABI      :: ElfOSABI   -- ^ OS\/ABI identification         , ehABIVersion :: Word8      -- ^ ABI version         , ehType       :: ElfType    -- ^ Object file type         , ehMachine    :: ElfMachine -- ^ Machine type         , ehEntry      :: WordXX c   -- ^ Entry point address         , ehFlags      :: Word32     -- ^ Processor-specific flags         }     | ElfSectionTable     | ElfSegmentTable     | ElfSection         { esName      :: String         -- ^ Section name (NB: string, not offset in the string table)         , esType      :: ElfSectionType -- ^ Section type         , esFlags     :: ElfSectionFlag -- ^ Section attributes         , esAddr      :: WordXX c       -- ^ Virtual address in memory         , esAddrAlign :: WordXX c       -- ^ Address alignment boundary         , esEntSize   :: WordXX c       -- ^ Size of entries, if section has table         , esN         :: ElfSectionIndex -- ^ Section number         , esInfo      :: Word32         -- ^ Miscellaneous information         , esLink      :: Word32         -- ^ Link to other section         , esData      :: ElfSectionData -- ^ The content of the section         }     | ElfSegment         { epType       :: ElfSegmentType -- ^ Type of segment         , epFlags      :: ElfSegmentFlag -- ^ Segment attributes         , epVirtAddr   :: WordXX c       -- ^ Virtual address in memory         , epPhysAddr   :: WordXX c       -- ^ Physical address         , epAddMemSize :: WordXX c       -- ^ Add this amount of memory after the section when the section is loaded to memory by execution system.                                          --   Or, in other words this is how much `pMemSize` is bigger than `pFileSize`         , epAlign      :: WordXX c       -- ^ Alignment of segment         , epData       :: [ElfXX c]      -- ^ Content of the segment         }     | ElfRawData -- ^ Some ELF files (some executables) don't bother to define                  -- sections for linking and have just raw data in segments.         { edData :: BSL.ByteString -- ^ Raw data in ELF file         }     | ElfRawAlign -- ^ Align the next data in the ELF file.                   -- The offset of the next data in the ELF file                   -- will be the minimal @x@ such that                   -- @x mod eaAlign == eaOffset mod eaAlign @         { eaOffset :: WordXX c -- ^ Align value         , eaAlign  :: WordXX c -- ^ Align module         }<\/code><\/pre>\n<p>\u041d\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d.<\/p>\n<ul>\n<li>\n<p>\u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 <code>ElfSection<\/code> \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u043d\u043e\u043c\u0435\u0440 \u0441\u0435\u043a\u0446\u0438\u0438.  \u041e\u043d \u043d\u0443\u0436\u0435\u043d, \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0441\u0435\u043a\u0446\u0438 \u043f\u043e \u0438\u0445 \u043d\u043e\u043c\u0435\u0440\u0430\u043c.  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0441\u0435\u043a\u0446\u0438\u0438 \u043f\u0440\u043e\u043d\u0443\u043c\u0435\u0440\u043e\u0432\u0430\u043d\u044b \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e, \u0442. \u0435. \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0446\u0435\u043b\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u043e\u0442 1 \u0434\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0435\u043a\u0446\u0438\u0439. \u0421\u0435\u043a\u0446\u0438\u044f \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c 0 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0443\u0441\u0442\u0430\u044f, \u043e\u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 <code>ElfHeader<\/code>, \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u0430\u043c\u044b\u043c \u043f\u0435\u0440\u0432\u044b\u043c \u043d\u0435\u043f\u0443\u0441\u0442\u044b\u043c \u0443\u0437\u043b\u043e\u043c \u0432 \u0434\u0435\u0440\u0435\u0432\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0443\u0437\u0435\u043b <code>ElfSection<\/code>, \u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043e\u0434\u0438\u043d \u0443\u0437\u0435\u043b <code>ElfSectionTable<\/code> \u0438 \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043e\u0434\u043d\u0430 \u0441\u0435\u043a\u0446\u0438\u044f, \u043f\u043e\u043b\u0435 <code>esData<\/code> \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0432\u043d\u043e <code>ElfSectionDataStringTable<\/code> (\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0442\u0440\u043e\u043a \u0434\u043b\u044f \u0438\u043c\u0451\u043d \u0441\u0435\u043a\u0446\u0438\u0439).<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0443\u0437\u0435\u043b <code>ElfSegment<\/code>, \u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043e\u0434\u0438\u043d \u0443\u0437\u0435\u043b <code>ElfSegmentTable<\/code>. <\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u043e\u0436\u043d\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>serializeElf<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf.html#v:serializeElf\">?<\/a> \u0438 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>parseElf<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf.html#v:parseElf\">?<\/a>:<\/p>\n<pre><code class=\"haskell\">serializeElf :: MonadThrow m => Elf -> m ByteString parseElf :: MonadCatch m => ByteString -> m Elf<\/code><\/pre>\n<p>\u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 <code>Binary<\/code> \u0434\u043b\u044f <code>ELF<\/code> \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d, \u0442\u0430\u043a \u043a\u0430\u043a <code>PutM<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/binary-0.10.0.0\/docs\/Data-Binary-Put.html#t:PutM\">?<\/a> \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430 <code>MonadFail<\/code>.<\/p>\n<h3>\u0410\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440 \u043a\u0430\u043a EDSL \u0434\u043b\u044f \u0425\u0430\u0441\u043a\u0435\u043b\u0430<\/h3>\n<p>\u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043c\u043e\u0434\u0443\u043b\u044c, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f AArch64 (\u0444\u0430\u0439\u043b <code>AsmAArch64.hs<\/code><a href=\"https:\/\/github.com\/aleksey-makarov\/melf\/blob\/v1.0.2\/examples\/AsmAArch64.hs\">?<\/a>). \u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 &#171;Hello World!&#187; \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.  \u0418\u0434\u0435\u044f \u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0430 \u0438\u0437 \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u044f\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0421\u0442\u0438\u0432\u0435\u043d\u0430 \u0414\u0438\u043b\u0430 &#171;\u041e\u0442 \u043c\u043e\u043d\u0430\u0434 \u043a \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443&#187; (<a href=\"https:\/\/www.stephendiehl.com\/posts\/monads_machine_code.html\">Stephen Diehl &#171;Monads to Machine Code&#187;<\/a>).  \u0422\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u043e\u043d\u0430\u0434\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <code>CodeState<\/code>.<\/p>\n<pre><code class=\"haskell\">data CodeState = CodeState     { offsetInPool    :: CodeOffset     , poolReversed    :: [Builder]     , codeReversed    :: [InstructionGen]     , symbolsRefersed :: [(String, Label)]     }<\/code><\/pre>\n<p><code>CodeState<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u0432, \u0441\u0430\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u0432, \u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432 \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.<\/p>\n<p>\u041c\u0430\u0441\u0441\u0438\u0432 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u0432 (literal pools) \u044d\u0442\u043e \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u0441\u0435\u043a\u0446\u0438\u0438 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u043a\u043e\u0434, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.  \u041a \u0442\u0430\u043a\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u043c \u043b\u0435\u0433\u043a\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0449\u0438\u0445 \u0430\u0434\u0440\u0435\u0441 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0430 \u043a\u043e\u043c\u0430\u043d\u0434.<\/p>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u043a \u0438 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u0432 \u0432\u0432\u0435\u0434\u0451\u043d \u0442\u0438\u043f <code>Label<\/code><\/p>\n<pre><code class=\"haskell\">newtype CodeOffset  = CodeOffset  { getCodeOffset  :: Int64 }     deriving (Eq, Show, Ord, Num, Enum, Real, Integral,     Bits, FiniteBits)  data Label = CodeRef CodeOffset            | PoolRef CodeOffset<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 <code>CodeRef<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043a\u043e\u0434 (\u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u043a):<\/p>\n<pre><code class=\"haskell\">label :: MonadState CodeState m => m Label label = gets (CodeRef . (* instructionSize)                       . fromIntegral                       . P.length                       . codeReversed)<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 <code>PoolRef<\/code> \u0445\u0440\u0430\u043d\u0438\u0442 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u0432.  \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f <code>CodeOffset<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>emitPool<\/code> (\u0441\u043c. \u043d\u0438\u0436\u0435).<\/p>\n<p>\u0412 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438\u0437 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0435\u043a\u0446\u0438\u0438 \u0438 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u0432 (\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0441\u0435\u0445 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u0430\u0441\u0441\u0438\u0432 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u0432 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u0434\u0430):<\/p>\n<pre><code class=\"haskell\">type InstructionGen = CodeOffset ->                       CodeOffset -> Either String Instruction<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>emit'<\/code>:<\/p>\n<pre><code class=\"haskell\">emit' :: MonadState CodeState m => InstructionGen -> m () emit' g = modify f where     f CodeState {..} = CodeState { codeReversed = g : codeReversed                                  , ..                                  }  emit :: MonadState CodeState m => Instruction -> m () emit i = emit' $ \\ _ _ -> Right i<\/code><\/pre>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0432\u0448\u0430\u044f\u0441\u044f \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 \u044d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"haskell\">-- | C6.2.317 SVC svc :: MonadState CodeState m => Word16 -> m () svc imm = emit $ 0xd4000001 .|. (fromIntegral imm `shift` 5)<\/code><\/pre>\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b AArch64 \u043c\u043e\u0433\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u043c\u0438 \u043a\u0430\u043a \u0441 64-\u0431\u0438\u0442\u043d\u044b\u043c\u0438 \u0438\u043b\u0438 \u043a\u0430\u043a \u0441 32-\u0431\u0438\u0442\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438.  \u0414\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u0440\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u043d\u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u0430: <code>x0<\/code>, <code>x1<\/code>&#8230; &#8212; \u0434\u043b\u044f 64-\u0431\u0438\u0442\u043d\u044b\u0445, <code>w0<\/code>, <code>w1<\/code>&#8230; &#8212; \u0434\u043b\u044f 32-\u0431\u0438\u0442\u043d\u044b\u0445. \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/wiki.haskell.org\/Phantom_type\">\u0444\u0430\u043d\u0442\u043e\u043c\u043d\u043e\u0433\u043e<\/a> \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"haskell\">data RegisterWidth = X | W  type Register :: RegisterWidth -> Type newtype Register c = R Word32  x0, x1 :: Register 'X x0 = R 0 x1 = R 1  w0, w1 :: Register 'W w0 = R 0 w1 = R 1  -- | C6.2.187 MOV (wide immediate) mov :: (MonadState CodeState m, SingI w) =>                               Register w ->                                   Word16 -> m ()<\/code><\/pre>\n<p>\u0412 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043a\u043e\u043c\u0430\u043d\u0434 AArch64 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>mov<\/code>.<br \/> \u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0441 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0448\u0438\u0440\u043e\u043a\u0438\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c (wide immediate).<\/p>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430 <code>adr<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u043c\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u0430\u043a \u0441 64-\u0431\u0438\u0442\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"haskell\">-- | C6.2.10 ADR adr :: MonadState CodeState m =>                   Register 'X ->                   Label -> m ()<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>emitPool<\/code>:<\/p>\n<pre><code class=\"haskell\">emitPool :: MonadState CodeState m =>                               Word ->                         ByteString -> m Label<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 &#8212; \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435, \u0432\u0442\u043e\u0440\u043e\u0439 &#8212; \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435.  \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0431\u0430\u0439\u0442 \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0440\u0430\u0432\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u0437\u0430\u043d\u043e\u0441\u0438\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043d\u0443\u043b\u0435\u0432\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u0430\u0439\u0442 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 <code>poolReversed<\/code>, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 \u044d\u0442\u043e\u0442 \u0436\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u0442 <code>offsetInPool<\/code>.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b <code>.ascii<\/code>:<\/p>\n<pre><code class=\"haskell\">ascii :: MonadState CodeState m => String -> m Label ascii s = emitPool 1 $ BSLC.pack s<\/code><\/pre>\n<p>\u0421\u0438\u043c\u0432\u043e\u043b\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u043c\u0435\u0442\u043e\u043a:<\/p>\n<pre><code class=\"haskell\">exportSymbol :: MonadState CodeState m => String -> Label -> m () exportSymbol s r = modify f where     f (CodeState {..}) = CodeState { symbolsRefersed = (s, r) : symbolsRefersed                                    , ..                                    }<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 &#171;Hello World!&#187; \u043d\u0430 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u043c \u0432 \u0425\u0430\u0441\u043a\u0435\u043b DSL (\u0444\u0430\u0439\u043b <code>HelloWorld.hs<\/code><a href=\"https:\/\/github.com\/aleksey-makarov\/melf\/blob\/v1.0.2\/examples\/HelloWorld.hs\">?<\/a>):<\/p>\n<pre><code class=\"haskell\">msg :: String msg = \"Hello World!\\n\"  -- | syscalls sysExit, sysWrite :: Word16 sysWrite = 64 sysExit = 93  helloWorld :: MonadCatch m => StateT CodeState m () helloWorld = do      start &lt;- label     exportSymbol \"_start\" start     mov x0 1     helloString &lt;- ascii msg     adr x1 helloString     mov x2 $ fromIntegral $ P.length msg     mov x8 sysWrite     svc 0      mov x0 0     mov x8 sysExit     svc 0<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0441\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043c\u0435\u0442\u043a\u0443, \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043d\u0438\u0436\u0435 \u043f\u043e \u043a\u043e\u0434\u0443, \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u043c\u043e\u043d\u0430\u0434\u0435 <code>MonadFix<\/code> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>mdo<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>do<\/code> (\u0441\u043c. \u0444\u0430\u0439\u043b <code>ForwardLabel.hs<\/code><a href=\"https:\/\/github.com\/aleksey-makarov\/melf\/blob\/v1.0.2\/examples\/ForwardLabel.hs\">?<\/a>).<\/p>\n<h3>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432<\/h3>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>assemble<\/code> (\u0441\u043c. <code>AsmAArch64.hs<\/code><a href=\"https:\/\/github.com\/aleksey-makarov\/melf\/blob\/v1.0.2\/examples\/AsmAArch64.hs\">?<\/a>) \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u0434 \u043d\u0430 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u043c \u0432 \u0425\u0430\u0441\u043a\u0435\u043b \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u0435 \u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0435 \u043a\u043e\u0434\u044b \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>Elf<\/code>:<\/p>\n<pre><code class=\"haskell\">assemble :: MonadCatch m => StateT CodeState m () -> m Elf<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u0443\u044e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043c\u043e\u043d\u0430\u0434\u0443 <code>State<\/code>, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0443\u044e \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0439 \u043a\u043e\u0434.  \u041a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u043c\u043e\u043d\u0430\u0434\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u043c \u0441\u0435\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u043e\u0434 (\u0441\u0435\u043a\u0446\u0438\u044f \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>.text<\/code>), \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, a \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0439 \u0444\u0430\u0439\u043b.  \u041d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0441\u0435\u043a\u0446\u0438\u0438 <code>.text<\/code> \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u0438\u043c\u044f <code>txt<\/code>, \u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 &#8212; \u0438\u043c\u044f <code>symbolTableData<\/code>, \u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u0442\u0440\u043e\u043a, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 &#8212; \u0438\u043c\u044f <code>stringTableData<\/code>:<\/p>\n<pre><code class=\"haskell\">    return $ SELFCLASS64 :&amp;: ElfList         [ ElfHeader             { ehData       = ELFDATA2LSB             , ehOSABI      = ELFOSABI_SYSV             , ehABIVersion = 0             , ehType       = ET_REL             , ehMachine    = EM_AARCH64             , ehEntry      = 0             , ehFlags      = 0             }         , ElfSection             { esName      = \".text\"             , esType      = SHT_PROGBITS             , esFlags     = SHF_EXECINSTR .|. SHF_ALLOC             , esAddr      = 0             , esAddrAlign = 8             , esEntSize   = 0             , esN         = textSecN             , esLink      = 0             , esInfo      = 0             , esData      = ElfSectionData txt             }         , ElfSection             { esName      = \".shstrtab\"             , esType      = SHT_STRTAB             , esFlags     = 0             , esAddr      = 0             , esAddrAlign = 1             , esEntSize   = 0             , esN         = shstrtabSecN             , esLink      = 0             , esInfo      = 0             , esData      = ElfSectionDataStringTable             }         , ElfSection             { esName      = \".symtab\"             , esType      = SHT_SYMTAB             , esFlags     = 0             , esAddr      = 0             , esAddrAlign = 8             , esEntSize   = symbolTableEntrySize ELFCLASS64             , esN         = symtabSecN             , esLink      = fromIntegral strtabSecN             , esInfo      = 1             , esData      = ElfSectionData symbolTableData             }         , ElfSection             { esName      = \".strtab\"             , esType      = SHT_STRTAB             , esFlags     = 0             , esAddr      = 0             , esAddrAlign = 1             , esEntSize   = 0             , esN         = strtabSecN             , esLink      = 0             , esInfo      = 0             , esData      = ElfSectionData stringTableData             }         , ElfSectionTable         ]<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u043c\u0435\u043d\u0430 \u0441 \u0441\u0443\u0444\u0444\u0438\u043a\u0441\u043e\u043c <code>SecN<\/code> (<code>textSecN<\/code>, <code>shstrtabSecN<\/code>, <code>symtabSecN<\/code>, <code>strtabSecN<\/code>) &#8212; \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u043d\u043e\u043c\u0435\u0440\u0430 \u0441\u0435\u043a\u0446\u0438\u0439, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0435 \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0432\u044b\u0448\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432<br \/> \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0435\u043a\u0446\u0438\u044f\u0445.  \u0412\u0441\u0451 \u044d\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0439, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u043e-\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c.<\/p>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0435\u0433\u043e \u0441\u043b\u0438\u043d\u043a\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code>[nix-shell:examples]$ ghci  GHCi, version 8.10.7: https:\/\/www.haskell.org\/ghc\/  :? for help Prelude> :l AsmAArch64.hs HelloWorld.hs  [1 of 2] Compiling AsmAArch64       ( AsmAArch64.hs, interpreted ) [2 of 2] Compiling HelloWorld       ( HelloWorld.hs, interpreted ) Ok, two modules loaded. *AsmAArch64> import HelloWorld *AsmAArch64 HelloWorld> elf &lt;- assemble helloWorld *AsmAArch64 HelloWorld> bs &lt;- serializeElf elf *AsmAArch64 HelloWorld> BSL.writeFile \"helloWorld.o\" bs *AsmAArch64 HelloWorld>  Leaving GHCi.  [nix-shell:examples]$ aarch64-unknown-linux-gnu-gcc -nostdlib helloWorld.o -o helloWorld  [nix-shell:examples]$ <\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u043b\u0438\u043d\u043a\u043e\u0432\u0449\u0438\u043a \u0431\u043b\u0430\u0433\u043e\u043f\u043e\u043b\u0443\u0447\u043d\u043e \u043f\u0440\u0438\u043d\u044f\u043b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0439 \u0444\u0430\u0439\u043b.  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code>[nix-shell:examples]$ qemu-aarch64 helloWorld Hello World!  [nix-shell:examples]$ <\/code><\/pre>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<h3>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432<\/h3>\n<p>\u041a\u043e\u0434 \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f <code>DummyLd<\/code><a href=\"https:\/\/github.com\/aleksey-makarov\/melf\/blob\/v1.0.2\/examples\/DummyLd.hs\">?<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0435\u043a\u0446\u0438\u044e <code>.text<\/code> \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u0444\u0430\u0439\u043b. \u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u0430\u043a\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u043d\u043e-\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c \u043a\u043e\u0434\u043e\u043c, \u043d\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u043c\u0441\u044f \u043d\u0430 \u043f\u043e\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043a\u043e\u0434\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0438\u0441\u0430\u043d \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435.<\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>dummyLd<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>Elf<\/code>, \u0438\u0449\u0435\u0442 \u0432 \u043d\u0451\u043c \u0441\u0435\u043a\u0446\u0438\u044e <code>.text <\/code>(\u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>elfFindSectionByName<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf.html#v:elfFindSectionByName\">?<\/a>) \u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a ELF (\u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>elfFindHeader<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf.html#v:elfFindHeader\">?<\/a>). \u0422\u0438\u043f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 <code>ET_EXEC<\/code>, \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0434\u0440\u0435\u0441, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043a\u043e\u0434\u0430 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u0435\u0433\u043c\u0435\u043d\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0438 \u0441\u043e\u0434\u0435\u0436\u0438\u043c\u043e\u0435 <code>.text<\/code>:<\/p>\n<pre><code class=\"haskell\">data MachineConfig (a :: ElfClass)     = MachineConfig         { mcAddress :: WordXX a -- ^ Virtual address of the executable segment         , mcAlign   :: WordXX a -- ^ Required alignment of the executable segment                                 --   in physical memory (depends on max page size)         }  getMachineConfig :: (IsElfClass a, MonadThrow m) => ElfMachine -> m (MachineConfig a) getMachineConfig EM_AARCH64 = return $ MachineConfig 0x400000 0x10000 getMachineConfig EM_X86_64  = return $ MachineConfig 0x400000 0x1000 getMachineConfig _          = $chainedError \"could not find machine config for this arch\"  dummyLd' :: forall a m . (MonadThrow m, IsElfClass a) => ElfList a -> m (ElfList a) dummyLd' (ElfList es) = do      txtSection &lt;- elfFindSectionByName es \".text\"     txtSectionData &lt;- case txtSection of         ElfSection { esData = ElfSectionData textData } -> return textData         _ -> $chainedError \"could not find correct \\\".text\\\" section\"      header &lt;- elfFindHeader es     case header of         ElfHeader { .. } -> do             MachineConfig { .. } &lt;- getMachineConfig ehMachine             return $ ElfList                 [ ElfSegment                     { epType       = PT_LOAD                     , epFlags      = PF_X .|. PF_R                     , epVirtAddr   = mcAddress                     , epPhysAddr   = mcAddress                     , epAddMemSize = 0                     , epAlign      = mcAlign                     , epData       =                         [ ElfHeader                             { ehType  = ET_EXEC                             , ehEntry = mcAddress + headerSize (fromSing $ sing @a)                             , ..                             }                         , ElfRawData                             { edData = txtSectionData                             }                         ]                     }                 , ElfSegmentTable                 ]         _ -> $chainedError \"could not find ELF header\"  -- | @dummyLd@ places the content of \".text\" section of the input ELF -- into the loadable segment of the resulting ELF. -- This could work if there are no relocations or references to external symbols. dummyLd :: MonadThrow m => Elf -> m Elf dummyLd (c :&amp;: l) = (c :&amp;:) &lt;$> withElfClass c dummyLd' l<\/code><\/pre>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0431\u0435\u0437 \u0443\u0447\u0430\u0441\u0442\u0438\u044f \u043b\u0438\u043d\u043a\u043e\u0432\u0449\u0438\u043a\u0430 GNU:<\/p>\n<pre><code>[nix-shell:examples]$ ghci GHCi, version 8.10.7: https:\/\/www.haskell.org\/ghc\/  :? for help Prelude> :l DummyLd.hs [1 of 1] Compiling DummyLd          ( DummyLd.hs, interpreted ) Ok, one module loaded. *DummyLd> import Data.ByteString.Lazy as BSL *DummyLd BSL> i &lt;- BSL.readFile \"helloWorld.o\" *DummyLd BSL> elf &lt;- parseElf i *DummyLd BSL> elf' &lt;- dummyLd elf *DummyLd BSL> o &lt;- serializeElf elf' *DummyLd BSL> BSL.writeFile \"helloWorld2\" o *DummyLd BSL>  Leaving GHCi.  [nix-shell:examples]$ chmod +x helloWorld2  [nix-shell:examples]$ qemu-aarch64 helloWorld2 Hello World!  [nix-shell:examples]$ <\/code><\/pre>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0434\u0430\u043d\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>melf<\/code> \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0432 \u0425\u0430\u0441\u043a\u0435\u043b DSL \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/auriga\/blog\/598363\/\"> https:\/\/habr.com\/ru\/company\/auriga\/blog\/598363\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\" class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 ELF &#8212; \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0442\u0435\u043c\u0430 \u043d\u0430 \u0425\u0430\u0431\u0440\u0435.  (<a href=\"https:\/\/habr.com\/ru\/post\/480642\/\">&#171;\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 ELF-\u0444\u0430\u0439\u043b\u044b \u0432 Linux: \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437&#187;<\/a>, <a href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/583576\/\">&#171;\u041c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0430\u0439\u043b\u0430 ELF \u2013 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432 2021?&#187;<\/a> \u0438 \u0442. \u0434.)<\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0425\u0430\u0441\u043a\u0435\u043b\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u044d\u0442\u0438\u043c\u0438 \u0444\u0430\u0439\u043b\u0430\u043c\u0438: <code>elf<\/code><br \/> (<a href=\"https:\/\/hackage.haskell.org\/package\/elf\">Hackage<\/a>) \u0438 <code>data-elf<\/code> (<a href=\"https:\/\/hackage.haskell.org\/package\/data-elf\">Hackage<\/a>).  \u042d\u0442\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438 \u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u043d\u0435 \u0434\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0439 \u0444\u0430\u0439\u043b.<\/p>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <code>melf<\/code> (<a href=\"https:\/\/github.com\/aleksey-makarov\/melf\">GitHub<\/a>, <a href=\"https:\/\/hackage.haskell.org\/package\/melf\">Hackage<\/a>) \u0434\u0430\u0451\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0444\u0430\u0439\u043b ELF \u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0444\u0430\u0439\u043b \u043f\u043e \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.  \u041d\u0438\u0436\u0435 \u0434\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0435\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<h3>\u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e ELF<\/h3>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 ELF \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u044b \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0444\u0430\u0439\u043b\u0430, \u0441\u0435\u043a\u0446\u0438\u0438, \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u044b, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0435\u043a\u0446\u0438\u0439, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432.  \u0421\u0435\u0433\u043c\u0435\u043d\u0442\u044b \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u043a\u043e\u043c\u043f\u0430\u043d\u043e\u0432\u0430\u043d\u044b \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u0436\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.  \u041f\u043e\u0440\u044f\u0434\u043e\u043a \u044d\u0442\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0444\u0430\u0439\u043b\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0444\u0430\u0439\u043b\u0430, \u0430 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u0435\u043a\u0446\u0438\u0439 \u0438 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0439. \u041a\u0430\u0436\u0434\u044b\u0439 \u0442\u0430\u043a\u043e\u0439 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u0432\u044b\u0440\u043e\u0432\u043d\u0435\u043d \u0432 \u0444\u0430\u0439\u043b\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u044b \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0430 \u0441\u0435\u043a\u0446\u0438\u0438 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 &#8212; \u043d\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043b\u043e\u0432\u0430.<\/p>\n<p>\u0412 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043e, \u0433\u0434\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0435\u043a\u0446\u0438\u0439 \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442, \u0433\u0434\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u0441\u0435\u043a\u0446\u0438\u0438 \u0438 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>\u0421\u0435\u0433\u043c\u0435\u043d\u0442\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0430 \u0441\u0435\u043a\u0446\u0438\u0438 \u044f \u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b \u043a\u0430\u043a \u043d\u0435\u0434\u0435\u043b\u0438\u043c\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430.  \u0412 \u0441\u0435\u043a\u0446\u0438\u044f\u0445 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u043a\u043e\u0434, \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.  \u041b\u0438\u043d\u043a\u043e\u0432\u0449\u0438\u043a \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0441\u0435\u043a\u0446\u0438\u0438 \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438 \u0432 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>\u0412\u043f\u043e\u043b\u043d\u0435 \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0444\u0430\u0439\u043b, \u0433\u0434\u0435 \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0435 \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u043a\u0430\u043a \u043a\u0430\u043a\u0430\u044f-\u043b\u0438\u0431\u043e \u0441\u0435\u043a\u0446\u0438\u044f.<\/p>\n<h3>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c<\/h3>\n<p>\u0412 \u043c\u043e\u0434\u0443\u043b\u0435 <code>Data.Elf.Headers<\/code> <a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html\">?<\/a> \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0440\u0430\u0437\u0431\u043e\u0440 \u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0444\u0430\u0439\u043b\u0430 ELF \u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u0435\u043a\u0446\u0438\u0439 \u0438 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432.  \u0414\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u0435\u043d\u0438\u044f 64- \u0438 32-\u0431\u0438\u0442\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0442\u0438\u043f  <code>ElfClass<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:ElfClass\">?<\/a><\/p>\n<pre><code class=\"haskell\">data ElfClass     = ELFCLASS32 -- ^ 32-bit ELF format     | ELFCLASS64 -- ^ 64-bit ELF format     deriving (Eq, Show)<\/code><\/pre>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u0435\u043a\u0446\u0438\u0439 \u0438 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0437\u043d\u0443\u044e \u0448\u0438\u0440\u0438\u043d\u0443 \u0432 \u0431\u0438\u0442\u0430\u0445, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0443\u044e \u043e\u0442  <code>ElfClass<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u0435\u043d \u0442\u0438\u043f <code>WordXX a<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:WordXX\">?<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 <code>data-elf<\/code>:<\/p>\n<pre><code class=\"haskell\">-- | @IsElfClass a@ is defined for each constructor of `ElfClass`. --   It defines @WordXX a@, which is `Word32` for `ELFCLASS32` --   and `Word64` for `ELFCLASS64`. class ( SingI c       , Typeable c       , Typeable (WordXX c)       , Data (WordXX c)       , Show (WordXX c)       , Read (WordXX c)       , Eq (WordXX c)       , Ord (WordXX c)       , Bounded (WordXX c)       , Enum (WordXX c)       , Num (WordXX c)       , Integral (WordXX c)       , Real (WordXX c)       , Bits (WordXX c)       , FiniteBits (WordXX c)       , Binary (Be (WordXX c))       , Binary (Le (WordXX c))       ) => IsElfClass c where     type WordXX c = r | r -> c  instance IsElfClass 'ELFCLASS32 where     type WordXX 'ELFCLASS32 = Word32  instance IsElfClass 'ELFCLASS64 where     type WordXX 'ELFCLASS64 = Word64<\/code><\/pre>\n<p>\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0444\u0430\u0439\u043b\u0430 ELF \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0438\u043f\u0430 <code>HeaderXX a<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:HeaderXX\">?<\/a>:<\/p>\n<pre><code class=\"haskell\">-- | Parsed ELF header data HeaderXX c =     HeaderXX         { hData       :: ElfData    -- ^ Data encoding (big- or little-endian)         , hOSABI      :: ElfOSABI   -- ^ OS\/ABI identification         , hABIVersion :: Word8      -- ^ ABI version         , hType       :: ElfType    -- ^ Object file type         , hMachine    :: ElfMachine -- ^ Machine type         , hEntry      :: WordXX c   -- ^ Entry point address         , hPhOff      :: WordXX c   -- ^ Program header offset         , hShOff      :: WordXX c   -- ^ Section header offset         , hFlags      :: Word32     -- ^ Processor-specific flags         , hPhEntSize  :: Word16     -- ^ Size of program header entry         , hPhNum      :: Word16     -- ^ Number of program header entries         , hShEntSize  :: Word16     -- ^ Size of section header entry         , hShNum      :: Word16     -- ^ Number of section header entries         , hShStrNdx   :: ElfSectionIndex -- ^ Section name string table index         }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u0434\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c\u0438 \u0441 \u0440\u0430\u0437\u043d\u043e\u0439 \u0448\u0438\u0440\u0438\u043d\u043e\u0439 \u0441\u043b\u043e\u0432\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0442\u0438\u043f <code>Header<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:Header\">?<\/a>:<\/p>\n<pre><code class=\"haskell\">-- | Sigma type where `ElfClass` defines the type of `HeaderXX` type Header = Sigma ElfClass (TyCon1 HeaderXX)<\/code><\/pre>\n<p><code>Header<\/code> \u044d\u0442\u043e \u043f\u0430\u0440\u0430, \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 &#8212; \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>ElfClass<\/code>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u0448\u0438\u0440\u0438\u043d\u0443 \u0441\u043b\u043e\u0432\u0430, \u0432\u0442\u043e\u0440\u043e\u0439 &#8212; <code>HeaderXX<\/code>, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c (\u03a3-\u0442\u0438\u043f \u0438\u0437 \u044f\u0437\u044b\u043a\u043e\u0432 \u0441 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438).  \u0414\u043b\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u03a3-\u0442\u0438\u043f\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <code>singletons<\/code> (<a href=\"https:\/\/hackage.haskell.org\/package\/singletons\">Hackage<\/a>,  <a href=\"https:\/\/blog.jle.im\/entry\/introduction-to-singletons-1.html\">&#171;Introduction to singletons&#187;<\/a>).<\/p>\n<p><code>Header<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430 <code>Binary<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/binary-0.10.0.0\/docs\/Data-Binary.html#t:Binary\">?<\/a>.  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0438\u043c\u0435\u044f \u043b\u0435\u043d\u0438\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0431\u0430\u0439\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0440\u0435\u0437\u043e\u043a \u0444\u0430\u0439\u043b\u0430 ELF, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u044d\u0442\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439:<\/p>\n<pre><code class=\"haskell\">withHeader ::                     BSL.ByteString ->     (forall a . IsElfClass a => HeaderXX a -> b) -> Either String b withHeader bs f =     case decodeOrFail bs of         Left (_, _, err) -> Left err         Right (_, _, (classS :&amp;: hxx) :: Header) ->             Right $ withElfClass classS f hxx<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c <code>decodeOrFail<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/binary-0.10.0.0\/docs\/Data-Binary.html#v:decodeOrFail\">?<\/a> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 <code>binary<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/binary\">?<\/a>, \u0430 <code>withElfClass<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#v:withElfClass\">?<\/a><br \/>\u0434\u0435\u043b\u0430\u0435\u0442 \u044f\u0432\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043b\u043e\u0432\u0430, \u043d\u0435\u044f\u0432\u043d\u044b\u043c (constraint).  \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 <code>withSingI<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/singletons-3.0.1\/docs\/Data-Singletons.html#v:withSingI\">?<\/a>:<\/p>\n<pre><code class=\"haskell\">-- | Convenience function for creating a -- context with an implicit ElfClass available. withElfClass :: Sing c -> (IsElfClass c => a) -> a withElfClass SELFCLASS64 x = x withElfClass SELFCLASS32 x = x<\/code><\/pre>\n<p>\u0412 <code>Data.Elf.Headers<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0442\u0430\u043a\u0436\u0435 \u0442\u0438\u043f\u044b <code>SectionXX<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:SectionXX\">?<\/a>, <code>SegmentXX<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:SegmentXX\">?<\/a> \u0438 <code>SymbolXX<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf-Headers.html#t:SymbolXX\">?<\/a> \u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u0435\u043a\u0446\u0438\u0439, \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.<\/p>\n<h3>\u0412\u0435\u0440\u0445\u043d\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c<\/h3>\n<p>\u0412 \u043c\u043e\u0434\u0443\u043b\u0435 <code>Data.Elf<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf.html\">?<\/a> \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u043f\u043e\u043b\u043d\u044b\u0435 \u0440\u0430\u0437\u0431\u043e\u0440 \u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 ELF.  \u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0444\u0430\u0439\u043b \u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a ELF, \u0442\u0430\u0431\u043b\u0438\u0446a \u0441\u0435\u043a\u0446\u0438\u0439 \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u044d\u0442\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 <code>ElfXX<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf.html#t:ElfXX\">?<\/a>,  \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0449\u0438\u0439 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0444\u0430\u0439\u043b\u0430 ELF.  \u041a\u0440\u043e\u043c\u0435 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0431\u043e\u0440\u0430, \u043f\u043e \u043d\u043e\u043c\u0435\u0440\u0430\u043c \u0441\u0435\u043a\u0446\u0438\u0439 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0438\u0445 \u0438\u043c\u0435\u043d\u0430.  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>Elf<\/code><a href=\"https:\/\/hackage.haskell.org\/package\/melf-1.0.1\/docs\/Data-Elf.html#t:Elf\">?<\/a>:<\/p>\n<pre><code class=\"haskell\">-- | `Elf` is a forrest of trees of type `ElfXX`. -- Trees are composed of `ElfXX` nodes, `ElfSegment` can contain subtrees newtype ElfList c = ElfList [ElfXX c]  -- | Elf is a sigma type where `ElfClass` defines the type of `ElfList` type Elf = Sigma ElfClass (TyCon1 ElfList)  -- | Section data may contain a string table. -- If a section contains a string table with section names, the data -- for such a section is generated and `esData` should contain `ElfSectionDataStringTable` data ElfSectionData     = ElfSectionData BSL.ByteString -- ^ Regular section data     | ElfSectionDataStringTable     -- ^ Section data will be generated from section names  -- | The type of node that defines Elf structure. data ElfXX (c :: ElfClass)     = ElfHeader         { ehData       :: ElfData    -- ^ Data encoding (big- or little-endian)         , ehOSABI      :: ElfOSABI   -- ^ OS\/ABI identification         , ehABIVersion :: Word8      -- ^ ABI version         , ehType       :: ElfType    -- ^ Object file type         , ehMachine    :: ElfMachine -- ^ Machine type         , ehEntry      :: WordXX c   -- ^ Entry point address         , ehFlags      :: Word32     -- ^ Processor-specific flags         }     | ElfSectionTable     | ElfSegmentTable     | ElfSection         { esName      :: String         -- ^ Section name (NB: string, not offset in the string table)         , esType      :: ElfSectionType -- ^ Section type         , esFlags     :: ElfSectionFlag -- ^ Section attributes         , esAddr      :: WordXX c       -- ^ Virtual address in memory         , esAddrAlign :: WordXX c       -- ^ Address alignment boundary         , esEntSize   :: WordXX c       -- ^ Size of entries, if section has table         , esN         :: ElfSectionIndex -- ^ Section number         , esInfo      :: Word32         -- ^ Miscellaneous information         , esLink      :: Word32         -- ^ Link to other section         , esData      :: ElfSectionData -- ^ The content of the section         }     | ElfSegment         { epType       :: ElfSegmentType -- ^ Type of segment         , epFlags      :: ElfSegmentFlag -- ^ Segment attributes         , epVirtAddr   :: WordXX c       -- ^ Virtual address in memory         , epPhysAddr   :: WordXX c       -- ^ Physical address         , epAddMemSize :: WordXX c       -- ^ Add this amount of memory after the section when the section is loaded to memory by execution system.                                          --   Or, in other words this is how much `pMemSize` is bigger than `pFileSize`         , epAlign      :: WordXX c       -- ^ Alignment of segment         , epData       :: [ElfXX c]      -- ^ Content of the segment         }     | ElfRawData -- ^ Some ELF files (some executables) don't bother to define                  -- sections for linking and have just raw data in segments.         { edData :: BSL.ByteString -- ^ Raw data in ELF file         }     | ElfRawAlign -- ^ Align the next data in the ELF file.                   -- The offset of the next data in the ELF file                   -- will be the minimal @x@ such that                   -- @x mod eaAlign == eaOffset mod eaAlign @         { eaOffset :: WordXX c -- ^ Align value         , eaAlign  :: WordXX c -- ^ Align module         }<\/code><\/pre>\n<p>\u041d\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d.<\/p>\n<ul>\n<li>\n<p>\u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 <code>ElfSection<\/code> \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u043d\u043e\u043c\u0435\u0440 \u0441\u0435\u043a\u0446\u0438\u0438.  \u041e\u043d \u043d\u0443\u0436\u0435\u043d, \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0441\u0435\u043a\u0446\u0438 \u043f\u043e \u0438\u0445 \u043d\u043e\u043c\u0435\u0440\u0430\u043c.  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0441\u0435\u043a\u0446\u0438\u0438 \u043f\u0440\u043e\u043d\u0443\u043c\u0435\u0440\u043e\u0432\u0430\u043d\u044b \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e, \u0442. \u0435. \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0446\u0435\u043b\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u043e\u0442 1 \u0434\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0435\u043a\u0446\u0438\u0439. \u0421\u0435\u043a\u0446\u0438\u044f \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c 0 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0443\u0441\u0442\u0430\u044f, \u043e\u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 <code>ElfHeader<\/code>, \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u0430\u043c\u044b\u043c \u043f\u0435\u0440\u0432\u044b\u043c \u043d\u0435\u043f\u0443\u0441\u0442\u044b\u043c \u0443\u0437\u043b\u043e\u043c \u0432 \u0434\u0435\u0440\u0435\u0432\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0443\u0437\u0435\u043b <code>ElfSection<\/code>, \u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043e\u0434\u0438\u043d \u0443\u0437\u0435\u043b <code>ElfSectionTable<\/code> \u0438 \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043e\u0434\u043d\u0430 \u0441\u0435\u043a\u0446\u0438\u044f, \u043f\u043e\u043b\u0435 <code>esData<\/code> \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0432\u043d\u043e <code>ElfSectionDataStringTable<\/code> (\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0442\u0440\u043e\u043a \u0434\u043b\u044f \u0438\u043c\u0451\u043d \u0441\u0435\u043a\u0446\u0438\u0439).<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0443\u0437\u0435\u043b <code>ElfSegment<\/code>, \u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043e\u0434\u0438\u043d \u0443\u0437\u0435\u043b <code>ElfSegmentTable<\/code>. <\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u0440\u0440<\/p>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-327255","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/327255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=327255"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/327255\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=327255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=327255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=327255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}