authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-17 13:13:03+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-17 13:13:03+01:00
logd1429a8fa98f85c9fb8d2bd99b7c31eb9de38b38
tree913955925f9976a200c9e72615cf06fc100a446a
parent509c7149b9f30e3271f2f8ba7669b95d2d240b9b

lib/std/elf: refactor reloc enum values


5 files changed, 356 insertions(+), 357 deletions(-)

lib/std/elf.zig+235-235
......@@ -1808,426 +1808,426 @@ pub const COMPRESS = enum(u32) {
18081808/// AMD x86-64 relocations.
18091809pub const R_X86_64 = enum(u32) {
18101810 /// No reloc
1811 R_X86_64_NONE = 0,
1811 NONE = 0,
18121812 /// Direct 64 bit
1813 R_X86_64_64 = 1,
1813 @"64" = 1,
18141814 /// PC relative 32 bit signed
1815 R_X86_64_PC32 = 2,
1815 PC32 = 2,
18161816 /// 32 bit GOT entry
1817 R_X86_64_GOT32 = 3,
1817 GOT32 = 3,
18181818 /// 32 bit PLT address
1819 R_X86_64_PLT32 = 4,
1819 PLT32 = 4,
18201820 /// Copy symbol at runtime
1821 R_X86_64_COPY = 5,
1821 COPY = 5,
18221822 /// Create GOT entry
1823 R_X86_64_GLOB_DAT = 6,
1823 GLOB_DAT = 6,
18241824 /// Create PLT entry
1825 R_X86_64_JUMP_SLOT = 7,
1825 JUMP_SLOT = 7,
18261826 /// Adjust by program base
1827 R_X86_64_RELATIVE = 8,
1827 RELATIVE = 8,
18281828 /// 32 bit signed PC relative offset to GOT
1829 R_X86_64_GOTPCREL = 9,
1829 GOTPCREL = 9,
18301830 /// Direct 32 bit zero extended
1831 R_X86_64_32 = 10,
1831 @"32" = 10,
18321832 /// Direct 32 bit sign extended
1833 R_X86_64_32S = 11,
1833 @"32S" = 11,
18341834 /// Direct 16 bit zero extended
1835 R_X86_64_16 = 12,
1835 @"16" = 12,
18361836 /// 16 bit sign extended pc relative
1837 R_X86_64_PC16 = 13,
1837 PC16 = 13,
18381838 /// Direct 8 bit sign extended
1839 R_X86_64_8 = 14,
1839 @"8" = 14,
18401840 /// 8 bit sign extended pc relative
1841 R_X86_64_PC8 = 15,
1841 PC8 = 15,
18421842 /// ID of module containing symbol
1843 R_X86_64_DTPMOD64 = 16,
1843 DTPMOD64 = 16,
18441844 /// Offset in module's TLS block
1845 R_X86_64_DTPOFF64 = 17,
1845 DTPOFF64 = 17,
18461846 /// Offset in initial TLS block
1847 R_X86_64_TPOFF64 = 18,
1847 TPOFF64 = 18,
18481848 /// 32 bit signed PC relative offset to two GOT entries for GD symbol
1849 R_X86_64_TLSGD = 19,
1849 TLSGD = 19,
18501850 /// 32 bit signed PC relative offset to two GOT entries for LD symbol
1851 R_X86_64_TLSLD = 20,
1851 TLSLD = 20,
18521852 /// Offset in TLS block
1853 R_X86_64_DTPOFF32 = 21,
1853 DTPOFF32 = 21,
18541854 /// 32 bit signed PC relative offset to GOT entry for IE symbol
1855 R_X86_64_GOTTPOFF = 22,
1855 GOTTPOFF = 22,
18561856 /// Offset in initial TLS block
1857 R_X86_64_TPOFF32 = 23,
1857 TPOFF32 = 23,
18581858 /// PC relative 64 bit
1859 R_X86_64_PC64 = 24,
1859 PC64 = 24,
18601860 /// 64 bit offset to GOT
1861 R_X86_64_GOTOFF64 = 25,
1861 GOTOFF64 = 25,
18621862 /// 32 bit signed pc relative offset to GOT
1863 R_X86_64_GOTPC32 = 26,
1863 GOTPC32 = 26,
18641864 /// 64 bit GOT entry offset
1865 R_X86_64_GOT64 = 27,
1865 GOT64 = 27,
18661866 /// 64 bit PC relative offset to GOT entry
1867 R_X86_64_GOTPCREL64 = 28,
1867 GOTPCREL64 = 28,
18681868 /// 64 bit PC relative offset to GOT
1869 R_X86_64_GOTPC64 = 29,
1869 GOTPC64 = 29,
18701870 /// Like GOT64, says PLT entry needed
1871 R_X86_64_GOTPLT64 = 30,
1871 GOTPLT64 = 30,
18721872 /// 64-bit GOT relative offset to PLT entry
1873 R_X86_64_PLTOFF64 = 31,
1873 PLTOFF64 = 31,
18741874 /// Size of symbol plus 32-bit addend
1875 R_X86_64_SIZE32 = 32,
1875 SIZE32 = 32,
18761876 /// Size of symbol plus 64-bit addend
1877 R_X86_64_SIZE64 = 33,
1877 SIZE64 = 33,
18781878 /// GOT offset for TLS descriptor
1879 R_X86_64_GOTPC32_TLSDESC = 34,
1879 GOTPC32_TLSDESC = 34,
18801880 /// Marker for call through TLS descriptor
1881 R_X86_64_TLSDESC_CALL = 35,
1881 TLSDESC_CALL = 35,
18821882 /// TLS descriptor
1883 R_X86_64_TLSDESC = 36,
1883 TLSDESC = 36,
18841884 /// Adjust indirectly by program base
1885 R_X86_64_IRELATIVE = 37,
1885 IRELATIVE = 37,
18861886 /// 64-bit adjust by program base
1887 R_X86_64_RELATIVE64 = 38,
1888 /// 39 Reserved was R_X86_64_PC32_BND
1889 /// 40 Reserved was R_X86_64_PLT32_BND
1887 RELATIVE64 = 38,
1888 /// 39 Reserved was PC32_BND
1889 /// 40 Reserved was PLT32_BND
18901890 /// Load from 32 bit signed pc relative offset to GOT entry without REX prefix, relaxable
1891 R_X86_64_GOTPCRELX = 41,
1891 GOTPCRELX = 41,
18921892 /// Load from 32 bit signed PC relative offset to GOT entry with REX prefix, relaxable
1893 R_X86_64_REX_GOTPCRELX = 42,
1893 REX_GOTPCRELX = 42,
18941894 _,
18951895};
18961896
18971897/// AArch64 relocs.
18981898pub const R_AARCH64 = enum(u32) {
18991899 /// No relocation.
1900 R_AARCH64_NONE = 0,
1900 NONE = 0,
19011901 /// ILP32 AArch64 relocs.
19021902 /// Direct 32 bit.
1903 R_AARCH64_P32_ABS32 = 1,
1903 P32_ABS32 = 1,
19041904 /// Copy symbol at runtime.
1905 R_AARCH64_P32_COPY = 180,
1905 P32_COPY = 180,
19061906 /// Create GOT entry.
1907 R_AARCH64_P32_GLOB_DAT = 181,
1907 P32_GLOB_DAT = 181,
19081908 /// Create PLT entry.
1909 R_AARCH64_P32_JUMP_SLOT = 182,
1909 P32_JUMP_SLOT = 182,
19101910 /// Adjust by program base.
1911 R_AARCH64_P32_RELATIVE = 183,
1911 P32_RELATIVE = 183,
19121912 /// Module number, 32 bit.
1913 R_AARCH64_P32_TLS_DTPMOD = 184,
1913 P32_TLS_DTPMOD = 184,
19141914 /// Module-relative offset, 32 bit.
1915 R_AARCH64_P32_TLS_DTPREL = 185,
1915 P32_TLS_DTPREL = 185,
19161916 /// TP-relative offset, 32 bit.
1917 R_AARCH64_P32_TLS_TPREL = 186,
1917 P32_TLS_TPREL = 186,
19181918 /// TLS Descriptor.
1919 R_AARCH64_P32_TLSDESC = 187,
1919 P32_TLSDESC = 187,
19201920 /// STT_GNU_IFUNC relocation.
1921 R_AARCH64_P32_IRELATIVE = 188,
1921 P32_IRELATIVE = 188,
19221922 /// LP64 AArch64 relocs.
19231923 /// Direct 64 bit.
1924 R_AARCH64_ABS64 = 257,
1924 ABS64 = 257,
19251925 /// Direct 32 bit.
1926 R_AARCH64_ABS32 = 258,
1926 ABS32 = 258,
19271927 /// Direct 16-bit.
1928 R_AARCH64_ABS16 = 259,
1928 ABS16 = 259,
19291929 /// PC-relative 64-bit.
1930 R_AARCH64_PREL64 = 260,
1930 PREL64 = 260,
19311931 /// PC-relative 32-bit.
1932 R_AARCH64_PREL32 = 261,
1932 PREL32 = 261,
19331933 /// PC-relative 16-bit.
1934 R_AARCH64_PREL16 = 262,
1934 PREL16 = 262,
19351935 /// Dir. MOVZ imm. from bits 15:0.
1936 R_AARCH64_MOVW_UABS_G0 = 263,
1936 MOVW_UABS_G0 = 263,
19371937 /// Likewise for MOVK; no check.
1938 R_AARCH64_MOVW_UABS_G0_NC = 264,
1938 MOVW_UABS_G0_NC = 264,
19391939 /// Dir. MOVZ imm. from bits 31:16.
1940 R_AARCH64_MOVW_UABS_G1 = 265,
1940 MOVW_UABS_G1 = 265,
19411941 /// Likewise for MOVK; no check.
1942 R_AARCH64_MOVW_UABS_G1_NC = 266,
1942 MOVW_UABS_G1_NC = 266,
19431943 /// Dir. MOVZ imm. from bits 47:32.
1944 R_AARCH64_MOVW_UABS_G2 = 267,
1944 MOVW_UABS_G2 = 267,
19451945 /// Likewise for MOVK; no check.
1946 R_AARCH64_MOVW_UABS_G2_NC = 268,
1946 MOVW_UABS_G2_NC = 268,
19471947 /// Dir. MOV{K,Z} imm. from 63:48.
1948 R_AARCH64_MOVW_UABS_G3 = 269,
1948 MOVW_UABS_G3 = 269,
19491949 /// Dir. MOV{N,Z} imm. from 15:0.
1950 R_AARCH64_MOVW_SABS_G0 = 270,
1950 MOVW_SABS_G0 = 270,
19511951 /// Dir. MOV{N,Z} imm. from 31:16.
1952 R_AARCH64_MOVW_SABS_G1 = 271,
1952 MOVW_SABS_G1 = 271,
19531953 /// Dir. MOV{N,Z} imm. from 47:32.
1954 R_AARCH64_MOVW_SABS_G2 = 272,
1954 MOVW_SABS_G2 = 272,
19551955 /// PC-rel. LD imm. from bits 20:2.
1956 R_AARCH64_LD_PREL_LO19 = 273,
1956 LD_PREL_LO19 = 273,
19571957 /// PC-rel. ADR imm. from bits 20:0.
1958 R_AARCH64_ADR_PREL_LO21 = 274,
1958 ADR_PREL_LO21 = 274,
19591959 /// Page-rel. ADRP imm. from 32:12.
1960 R_AARCH64_ADR_PREL_PG_HI21 = 275,
1960 ADR_PREL_PG_HI21 = 275,
19611961 /// Likewise; no overflow check.
1962 R_AARCH64_ADR_PREL_PG_HI21_NC = 276,
1962 ADR_PREL_PG_HI21_NC = 276,
19631963 /// Dir. ADD imm. from bits 11:0.
1964 R_AARCH64_ADD_ABS_LO12_NC = 277,
1964 ADD_ABS_LO12_NC = 277,
19651965 /// Likewise for LD/ST; no check.
1966 R_AARCH64_LDST8_ABS_LO12_NC = 278,
1966 LDST8_ABS_LO12_NC = 278,
19671967 /// PC-rel. TBZ/TBNZ imm. from 15:2.
1968 R_AARCH64_TSTBR14 = 279,
1968 TSTBR14 = 279,
19691969 /// PC-rel. cond. br. imm. from 20:2.
1970 R_AARCH64_CONDBR19 = 280,
1970 CONDBR19 = 280,
19711971 /// PC-rel. B imm. from bits 27:2.
1972 R_AARCH64_JUMP26 = 282,
1972 JUMP26 = 282,
19731973 /// Likewise for CALL.
1974 R_AARCH64_CALL26 = 283,
1974 CALL26 = 283,
19751975 /// Dir. ADD imm. from bits 11:1.
1976 R_AARCH64_LDST16_ABS_LO12_NC = 284,
1976 LDST16_ABS_LO12_NC = 284,
19771977 /// Likewise for bits 11:2.
1978 R_AARCH64_LDST32_ABS_LO12_NC = 285,
1978 LDST32_ABS_LO12_NC = 285,
19791979 /// Likewise for bits 11:3.
1980 R_AARCH64_LDST64_ABS_LO12_NC = 286,
1980 LDST64_ABS_LO12_NC = 286,
19811981 /// PC-rel. MOV{N,Z} imm. from 15:0.
1982 R_AARCH64_MOVW_PREL_G0 = 287,
1982 MOVW_PREL_G0 = 287,
19831983 /// Likewise for MOVK; no check.
1984 R_AARCH64_MOVW_PREL_G0_NC = 288,
1984 MOVW_PREL_G0_NC = 288,
19851985 /// PC-rel. MOV{N,Z} imm. from 31:16.
1986 R_AARCH64_MOVW_PREL_G1 = 289,
1986 MOVW_PREL_G1 = 289,
19871987 /// Likewise for MOVK; no check.
1988 R_AARCH64_MOVW_PREL_G1_NC = 290,
1988 MOVW_PREL_G1_NC = 290,
19891989 /// PC-rel. MOV{N,Z} imm. from 47:32.
1990 R_AARCH64_MOVW_PREL_G2 = 291,
1990 MOVW_PREL_G2 = 291,
19911991 /// Likewise for MOVK; no check.
1992 R_AARCH64_MOVW_PREL_G2_NC = 292,
1992 MOVW_PREL_G2_NC = 292,
19931993 /// PC-rel. MOV{N,Z} imm. from 63:48.
1994 R_AARCH64_MOVW_PREL_G3 = 293,
1994 MOVW_PREL_G3 = 293,
19951995 /// Dir. ADD imm. from bits 11:4.
1996 R_AARCH64_LDST128_ABS_LO12_NC = 299,
1996 LDST128_ABS_LO12_NC = 299,
19971997 /// GOT-rel. off. MOV{N,Z} imm. 15:0.
1998 R_AARCH64_MOVW_GOTOFF_G0 = 300,
1998 MOVW_GOTOFF_G0 = 300,
19991999 /// Likewise for MOVK; no check.
2000 R_AARCH64_MOVW_GOTOFF_G0_NC = 301,
2000 MOVW_GOTOFF_G0_NC = 301,
20012001 /// GOT-rel. o. MOV{N,Z} imm. 31:16.
2002 R_AARCH64_MOVW_GOTOFF_G1 = 302,
2002 MOVW_GOTOFF_G1 = 302,
20032003 /// Likewise for MOVK; no check.
2004 R_AARCH64_MOVW_GOTOFF_G1_NC = 303,
2004 MOVW_GOTOFF_G1_NC = 303,
20052005 /// GOT-rel. o. MOV{N,Z} imm. 47:32.
2006 R_AARCH64_MOVW_GOTOFF_G2 = 304,
2006 MOVW_GOTOFF_G2 = 304,
20072007 /// Likewise for MOVK; no check.
2008 R_AARCH64_MOVW_GOTOFF_G2_NC = 305,
2008 MOVW_GOTOFF_G2_NC = 305,
20092009 /// GOT-rel. o. MOV{N,Z} imm. 63:48.
2010 R_AARCH64_MOVW_GOTOFF_G3 = 306,
2010 MOVW_GOTOFF_G3 = 306,
20112011 /// GOT-relative 64-bit.
2012 R_AARCH64_GOTREL64 = 307,
2012 GOTREL64 = 307,
20132013 /// GOT-relative 32-bit.
2014 R_AARCH64_GOTREL32 = 308,
2014 GOTREL32 = 308,
20152015 /// PC-rel. GOT off. load imm. 20:2.
2016 R_AARCH64_GOT_LD_PREL19 = 309,
2016 GOT_LD_PREL19 = 309,
20172017 /// GOT-rel. off. LD/ST imm. 14:3.
2018 R_AARCH64_LD64_GOTOFF_LO15 = 310,
2018 LD64_GOTOFF_LO15 = 310,
20192019 /// P-page-rel. GOT off. ADRP 32:12.
2020 R_AARCH64_ADR_GOT_PAGE = 311,
2020 ADR_GOT_PAGE = 311,
20212021 /// Dir. GOT off. LD/ST imm. 11:3.
2022 R_AARCH64_LD64_GOT_LO12_NC = 312,
2022 LD64_GOT_LO12_NC = 312,
20232023 /// GOT-page-rel. GOT off. LD/ST 14:3
2024 R_AARCH64_LD64_GOTPAGE_LO15 = 313,
2024 LD64_GOTPAGE_LO15 = 313,
20252025 /// PC-relative ADR imm. 20:0.
2026 R_AARCH64_TLSGD_ADR_PREL21 = 512,
2026 TLSGD_ADR_PREL21 = 512,
20272027 /// page-rel. ADRP imm. 32:12.
2028 R_AARCH64_TLSGD_ADR_PAGE21 = 513,
2028 TLSGD_ADR_PAGE21 = 513,
20292029 /// direct ADD imm. from 11:0.
2030 R_AARCH64_TLSGD_ADD_LO12_NC = 514,
2030 TLSGD_ADD_LO12_NC = 514,
20312031 /// GOT-rel. MOV{N,Z} 31:16.
2032 R_AARCH64_TLSGD_MOVW_G1 = 515,
2032 TLSGD_MOVW_G1 = 515,
20332033 /// GOT-rel. MOVK imm. 15:0.
2034 R_AARCH64_TLSGD_MOVW_G0_NC = 516,
2034 TLSGD_MOVW_G0_NC = 516,
20352035 /// Like 512; local dynamic model.
2036 R_AARCH64_TLSLD_ADR_PREL21 = 517,
2036 TLSLD_ADR_PREL21 = 517,
20372037 /// Like 513; local dynamic model.
2038 R_AARCH64_TLSLD_ADR_PAGE21 = 518,
2038 TLSLD_ADR_PAGE21 = 518,
20392039 /// Like 514; local dynamic model.
2040 R_AARCH64_TLSLD_ADD_LO12_NC = 519,
2040 TLSLD_ADD_LO12_NC = 519,
20412041 /// Like 515; local dynamic model.
2042 R_AARCH64_TLSLD_MOVW_G1 = 520,
2042 TLSLD_MOVW_G1 = 520,
20432043 /// Like 516; local dynamic model.
2044 R_AARCH64_TLSLD_MOVW_G0_NC = 521,
2044 TLSLD_MOVW_G0_NC = 521,
20452045 /// TLS PC-rel. load imm. 20:2.
2046 R_AARCH64_TLSLD_LD_PREL19 = 522,
2046 TLSLD_LD_PREL19 = 522,
20472047 /// TLS DTP-rel. MOV{N,Z} 47:32.
2048 R_AARCH64_TLSLD_MOVW_DTPREL_G2 = 523,
2048 TLSLD_MOVW_DTPREL_G2 = 523,
20492049 /// TLS DTP-rel. MOV{N,Z} 31:16.
2050 R_AARCH64_TLSLD_MOVW_DTPREL_G1 = 524,
2050 TLSLD_MOVW_DTPREL_G1 = 524,
20512051 /// Likewise; MOVK; no check.
2052 R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC = 525,
2052 TLSLD_MOVW_DTPREL_G1_NC = 525,
20532053 /// TLS DTP-rel. MOV{N,Z} 15:0.
2054 R_AARCH64_TLSLD_MOVW_DTPREL_G0 = 526,
2054 TLSLD_MOVW_DTPREL_G0 = 526,
20552055 /// Likewise; MOVK; no check.
2056 R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC = 527,
2056 TLSLD_MOVW_DTPREL_G0_NC = 527,
20572057 /// DTP-rel. ADD imm. from 23:12.
2058 R_AARCH64_TLSLD_ADD_DTPREL_HI12 = 528,
2058 TLSLD_ADD_DTPREL_HI12 = 528,
20592059 /// DTP-rel. ADD imm. from 11:0.
2060 R_AARCH64_TLSLD_ADD_DTPREL_LO12 = 529,
2060 TLSLD_ADD_DTPREL_LO12 = 529,
20612061 /// Likewise; no ovfl. check.
2062 R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC = 530,
2062 TLSLD_ADD_DTPREL_LO12_NC = 530,
20632063 /// DTP-rel. LD/ST imm. 11:0.
2064 R_AARCH64_TLSLD_LDST8_DTPREL_LO12 = 531,
2064 TLSLD_LDST8_DTPREL_LO12 = 531,
20652065 /// Likewise; no check.
2066 R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC = 532,
2066 TLSLD_LDST8_DTPREL_LO12_NC = 532,
20672067 /// DTP-rel. LD/ST imm. 11:1.
2068 R_AARCH64_TLSLD_LDST16_DTPREL_LO12 = 533,
2068 TLSLD_LDST16_DTPREL_LO12 = 533,
20692069 /// Likewise; no check.
2070 R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC = 534,
2070 TLSLD_LDST16_DTPREL_LO12_NC = 534,
20712071 /// DTP-rel. LD/ST imm. 11:2.
2072 R_AARCH64_TLSLD_LDST32_DTPREL_LO12 = 535,
2072 TLSLD_LDST32_DTPREL_LO12 = 535,
20732073 /// Likewise; no check.
2074 R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC = 536,
2074 TLSLD_LDST32_DTPREL_LO12_NC = 536,
20752075 /// DTP-rel. LD/ST imm. 11:3.
2076 R_AARCH64_TLSLD_LDST64_DTPREL_LO12 = 537,
2076 TLSLD_LDST64_DTPREL_LO12 = 537,
20772077 /// Likewise; no check.
2078 R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC = 538,
2078 TLSLD_LDST64_DTPREL_LO12_NC = 538,
20792079 /// GOT-rel. MOV{N,Z} 31:16.
2080 R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 = 539,
2080 TLSIE_MOVW_GOTTPREL_G1 = 539,
20812081 /// GOT-rel. MOVK 15:0.
2082 R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC = 540,
2082 TLSIE_MOVW_GOTTPREL_G0_NC = 540,
20832083 /// Page-rel. ADRP 32:12.
2084 R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 = 541,
2084 TLSIE_ADR_GOTTPREL_PAGE21 = 541,
20852085 /// Direct LD off. 11:3.
2086 R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC = 542,
2086 TLSIE_LD64_GOTTPREL_LO12_NC = 542,
20872087 /// PC-rel. load imm. 20:2.
2088 R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 = 543,
2088 TLSIE_LD_GOTTPREL_PREL19 = 543,
20892089 /// TLS TP-rel. MOV{N,Z} 47:32.
2090 R_AARCH64_TLSLE_MOVW_TPREL_G2 = 544,
2090 TLSLE_MOVW_TPREL_G2 = 544,
20912091 /// TLS TP-rel. MOV{N,Z} 31:16.
2092 R_AARCH64_TLSLE_MOVW_TPREL_G1 = 545,
2092 TLSLE_MOVW_TPREL_G1 = 545,
20932093 /// Likewise; MOVK; no check.
2094 R_AARCH64_TLSLE_MOVW_TPREL_G1_NC = 546,
2094 TLSLE_MOVW_TPREL_G1_NC = 546,
20952095 /// TLS TP-rel. MOV{N,Z} 15:0.
2096 R_AARCH64_TLSLE_MOVW_TPREL_G0 = 547,
2096 TLSLE_MOVW_TPREL_G0 = 547,
20972097 /// Likewise; MOVK; no check.
2098 R_AARCH64_TLSLE_MOVW_TPREL_G0_NC = 548,
2098 TLSLE_MOVW_TPREL_G0_NC = 548,
20992099 /// TP-rel. ADD imm. 23:12.
2100 R_AARCH64_TLSLE_ADD_TPREL_HI12 = 549,
2100 TLSLE_ADD_TPREL_HI12 = 549,
21012101 /// TP-rel. ADD imm. 11:0.
2102 R_AARCH64_TLSLE_ADD_TPREL_LO12 = 550,
2102 TLSLE_ADD_TPREL_LO12 = 550,
21032103 /// Likewise; no ovfl. check.
2104 R_AARCH64_TLSLE_ADD_TPREL_LO12_NC = 551,
2104 TLSLE_ADD_TPREL_LO12_NC = 551,
21052105 /// TP-rel. LD/ST off. 11:0.
2106 R_AARCH64_TLSLE_LDST8_TPREL_LO12 = 552,
2106 TLSLE_LDST8_TPREL_LO12 = 552,
21072107 /// Likewise; no ovfl. check.
2108 R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC = 553,
2108 TLSLE_LDST8_TPREL_LO12_NC = 553,
21092109 /// TP-rel. LD/ST off. 11:1.
2110 R_AARCH64_TLSLE_LDST16_TPREL_LO12 = 554,
2110 TLSLE_LDST16_TPREL_LO12 = 554,
21112111 /// Likewise; no check.
2112 R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC = 555,
2112 TLSLE_LDST16_TPREL_LO12_NC = 555,
21132113 /// TP-rel. LD/ST off. 11:2.
2114 R_AARCH64_TLSLE_LDST32_TPREL_LO12 = 556,
2114 TLSLE_LDST32_TPREL_LO12 = 556,
21152115 /// Likewise; no check.
2116 R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC = 557,
2116 TLSLE_LDST32_TPREL_LO12_NC = 557,
21172117 /// TP-rel. LD/ST off. 11:3.
2118 R_AARCH64_TLSLE_LDST64_TPREL_LO12 = 558,
2118 TLSLE_LDST64_TPREL_LO12 = 558,
21192119 /// Likewise; no check.
2120 R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC = 559,
2120 TLSLE_LDST64_TPREL_LO12_NC = 559,
21212121 /// PC-rel. load immediate 20:2.
2122 R_AARCH64_TLSDESC_LD_PREL19 = 560,
2122 TLSDESC_LD_PREL19 = 560,
21232123 /// PC-rel. ADR immediate 20:0.
2124 R_AARCH64_TLSDESC_ADR_PREL21 = 561,
2124 TLSDESC_ADR_PREL21 = 561,
21252125 /// Page-rel. ADRP imm. 32:12.
2126 R_AARCH64_TLSDESC_ADR_PAGE21 = 562,
2126 TLSDESC_ADR_PAGE21 = 562,
21272127 /// Direct LD off. from 11:3.
2128 R_AARCH64_TLSDESC_LD64_LO12 = 563,
2128 TLSDESC_LD64_LO12 = 563,
21292129 /// Direct ADD imm. from 11:0.
2130 R_AARCH64_TLSDESC_ADD_LO12 = 564,
2130 TLSDESC_ADD_LO12 = 564,
21312131 /// GOT-rel. MOV{N,Z} imm. 31:16.
2132 R_AARCH64_TLSDESC_OFF_G1 = 565,
2132 TLSDESC_OFF_G1 = 565,
21332133 /// GOT-rel. MOVK imm. 15:0; no ck.
2134 R_AARCH64_TLSDESC_OFF_G0_NC = 566,
2134 TLSDESC_OFF_G0_NC = 566,
21352135 /// Relax LDR.
2136 R_AARCH64_TLSDESC_LDR = 567,
2136 TLSDESC_LDR = 567,
21372137 /// Relax ADD.
2138 R_AARCH64_TLSDESC_ADD = 568,
2138 TLSDESC_ADD = 568,
21392139 /// Relax BLR.
2140 R_AARCH64_TLSDESC_CALL = 569,
2140 TLSDESC_CALL = 569,
21412141 /// TP-rel. LD/ST off. 11:4.
2142 R_AARCH64_TLSLE_LDST128_TPREL_LO12 = 570,
2142 TLSLE_LDST128_TPREL_LO12 = 570,
21432143 /// Likewise; no check.
2144 R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC = 571,
2144 TLSLE_LDST128_TPREL_LO12_NC = 571,
21452145 /// DTP-rel. LD/ST imm. 11:4.
2146 R_AARCH64_TLSLD_LDST128_DTPREL_LO12 = 572,
2146 TLSLD_LDST128_DTPREL_LO12 = 572,
21472147 /// Likewise; no check.
2148 R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC = 573,
2148 TLSLD_LDST128_DTPREL_LO12_NC = 573,
21492149 /// Copy symbol at runtime.
2150 R_AARCH64_COPY = 1024,
2150 COPY = 1024,
21512151 /// Create GOT entry.
2152 R_AARCH64_GLOB_DAT = 1025,
2152 GLOB_DAT = 1025,
21532153 /// Create PLT entry.
2154 R_AARCH64_JUMP_SLOT = 1026,
2154 JUMP_SLOT = 1026,
21552155 /// Adjust by program base.
2156 R_AARCH64_RELATIVE = 1027,
2156 RELATIVE = 1027,
21572157 /// Module number, 64 bit.
2158 R_AARCH64_TLS_DTPMOD = 1028,
2158 TLS_DTPMOD = 1028,
21592159 /// Module-relative offset, 64 bit.
2160 R_AARCH64_TLS_DTPREL = 1029,
2160 TLS_DTPREL = 1029,
21612161 /// TP-relative offset, 64 bit.
2162 R_AARCH64_TLS_TPREL = 1030,
2162 TLS_TPREL = 1030,
21632163 /// TLS Descriptor.
2164 R_AARCH64_TLSDESC = 1031,
2164 TLSDESC = 1031,
21652165 /// STT_GNU_IFUNC relocation.
2166 R_AARCH64_IRELATIVE = 1032,
2166 IRELATIVE = 1032,
21672167 _,
21682168};
21692169
21702170/// RISC-V relocations.
21712171pub const R_RISCV = enum(u32) {
2172 R_RISCV_NONE = 0,
2173 R_RISCV_32 = 1,
2174 R_RISCV_64 = 2,
2175 R_RISCV_RELATIVE = 3,
2176 R_RISCV_COPY = 4,
2177 R_RISCV_JUMP_SLOT = 5,
2178 R_RISCV_TLS_DTPMOD32 = 6,
2179 R_RISCV_TLS_DTPMOD64 = 7,
2180 R_RISCV_TLS_DTPREL32 = 8,
2181 R_RISCV_TLS_DTPREL64 = 9,
2182 R_RISCV_TLS_TPREL32 = 10,
2183 R_RISCV_TLS_TPREL64 = 11,
2184 R_RISCV_TLSDESC = 12,
2185 R_RISCV_BRANCH = 16,
2186 R_RISCV_JAL = 17,
2187 R_RISCV_CALL = 18,
2188 R_RISCV_CALL_PLT = 19,
2189 R_RISCV_GOT_HI20 = 20,
2190 R_RISCV_TLS_GOT_HI20 = 21,
2191 R_RISCV_TLS_GD_HI20 = 22,
2192 R_RISCV_PCREL_HI20 = 23,
2193 R_RISCV_PCREL_LO12_I = 24,
2194 R_RISCV_PCREL_LO12_S = 25,
2195 R_RISCV_HI20 = 26,
2196 R_RISCV_LO12_I = 27,
2197 R_RISCV_LO12_S = 28,
2198 R_RISCV_TPREL_HI20 = 29,
2199 R_RISCV_TPREL_LO12_I = 30,
2200 R_RISCV_TPREL_LO12_S = 31,
2201 R_RISCV_TPREL_ADD = 32,
2202 R_RISCV_ADD8 = 33,
2203 R_RISCV_ADD16 = 34,
2204 R_RISCV_ADD32 = 35,
2205 R_RISCV_ADD64 = 36,
2206 R_RISCV_SUB8 = 37,
2207 R_RISCV_SUB16 = 38,
2208 R_RISCV_SUB32 = 39,
2209 R_RISCV_SUB64 = 40,
2210 R_RISCV_GNU_VTINHERIT = 41,
2211 R_RISCV_GNU_VTENTRY = 42,
2212 R_RISCV_ALIGN = 43,
2213 R_RISCV_RVC_BRANCH = 44,
2214 R_RISCV_RVC_JUMP = 45,
2215 R_RISCV_RVC_LUI = 46,
2216 R_RISCV_GPREL_I = 47,
2217 R_RISCV_GPREL_S = 48,
2218 R_RISCV_TPREL_I = 49,
2219 R_RISCV_TPREL_S = 50,
2220 R_RISCV_RELAX = 51,
2221 R_RISCV_SUB6 = 52,
2222 R_RISCV_SET6 = 53,
2223 R_RISCV_SET8 = 54,
2224 R_RISCV_SET16 = 55,
2225 R_RISCV_SET32 = 56,
2226 R_RISCV_32_PCREL = 57,
2227 R_RISCV_IRELATIVE = 58,
2228 R_RISCV_PLT32 = 59,
2229 R_RISCV_SET_ULEB128 = 60,
2230 R_RISCV_SUB_ULEB128 = 61,
2172 NONE = 0,
2173 @"32" = 1,
2174 @"64" = 2,
2175 RELATIVE = 3,
2176 COPY = 4,
2177 JUMP_SLOT = 5,
2178 TLS_DTPMOD32 = 6,
2179 TLS_DTPMOD64 = 7,
2180 TLS_DTPREL32 = 8,
2181 TLS_DTPREL64 = 9,
2182 TLS_TPREL32 = 10,
2183 TLS_TPREL64 = 11,
2184 TLSDESC = 12,
2185 BRANCH = 16,
2186 JAL = 17,
2187 CALL = 18,
2188 CALL_PLT = 19,
2189 GOT_HI20 = 20,
2190 TLS_GOT_HI20 = 21,
2191 TLS_GD_HI20 = 22,
2192 PCREL_HI20 = 23,
2193 PCREL_LO12_I = 24,
2194 PCREL_LO12_S = 25,
2195 HI20 = 26,
2196 LO12_I = 27,
2197 LO12_S = 28,
2198 TPREL_HI20 = 29,
2199 TPREL_LO12_I = 30,
2200 TPREL_LO12_S = 31,
2201 TPREL_ADD = 32,
2202 ADD8 = 33,
2203 ADD16 = 34,
2204 ADD32 = 35,
2205 ADD64 = 36,
2206 SUB8 = 37,
2207 SUB16 = 38,
2208 SUB32 = 39,
2209 SUB64 = 40,
2210 GNU_VTINHERIT = 41,
2211 GNU_VTENTRY = 42,
2212 ALIGN = 43,
2213 RVC_BRANCH = 44,
2214 RVC_JUMP = 45,
2215 RVC_LUI = 46,
2216 GPREL_I = 47,
2217 GPREL_S = 48,
2218 TPREL_I = 49,
2219 TPREL_S = 50,
2220 RELAX = 51,
2221 SUB6 = 52,
2222 SET6 = 53,
2223 SET8 = 54,
2224 SET16 = 55,
2225 SET32 = 56,
2226 @"32_PCREL" = 57,
2227 IRELATIVE = 58,
2228 PLT32 = 59,
2229 SET_ULEB128 = 60,
2230 SUB_ULEB128 = 61,
22312231 _,
22322232};
22332233
src/arch/x86_64/Emit.zig+9-9
......@@ -43,7 +43,7 @@ pub fn emitMir(emit: *Emit) Error!void {
4343 .linker_extern_fn => |symbol| if (emit.lower.bin_file.cast(link.File.Elf)) |elf_file| {
4444 // Add relocation to the decl.
4545 const atom_ptr = elf_file.symbol(symbol.atom_index).atom(elf_file).?;
46 const r_type = @intFromEnum(std.elf.R_X86_64.R_X86_64_PLT32);
46 const r_type = @intFromEnum(std.elf.R_X86_64.PLT32);
4747 try atom_ptr.addReloc(elf_file, .{
4848 .r_offset = end_offset - 4,
4949 .r_info = (@as(u64, @intCast(symbol.sym_index)) << 32) | r_type,
......@@ -89,7 +89,7 @@ pub fn emitMir(emit: *Emit) Error!void {
8989 .linker_tlsld => |data| {
9090 const elf_file = emit.lower.bin_file.cast(link.File.Elf).?;
9191 const atom = elf_file.symbol(data.atom_index).atom(elf_file).?;
92 const r_type = @intFromEnum(std.elf.R_X86_64.R_X86_64_TLSLD);
92 const r_type = @intFromEnum(std.elf.R_X86_64.TLSLD);
9393 try atom.addReloc(elf_file, .{
9494 .r_offset = end_offset - 4,
9595 .r_info = (@as(u64, @intCast(data.sym_index)) << 32) | r_type,
......@@ -99,7 +99,7 @@ pub fn emitMir(emit: *Emit) Error!void {
9999 .linker_dtpoff => |data| {
100100 const elf_file = emit.lower.bin_file.cast(link.File.Elf).?;
101101 const atom = elf_file.symbol(data.atom_index).atom(elf_file).?;
102 const r_type = @intFromEnum(std.elf.R_X86_64.R_X86_64_DTPOFF32);
102 const r_type = @intFromEnum(std.elf.R_X86_64.DTPOFF32);
103103 try atom.addReloc(elf_file, .{
104104 .r_offset = end_offset - 4,
105105 .r_info = (@as(u64, @intCast(data.sym_index)) << 32) | r_type,
......@@ -122,9 +122,9 @@ pub fn emitMir(emit: *Emit) Error!void {
122122 const r_type: u32 = if (sym.flags.needs_zig_got and !is_obj_or_static_lib)
123123 link.File.Elf.R_ZIG_GOTPCREL
124124 else if (sym.flags.needs_got)
125 @intFromEnum(std.elf.R_X86_64.R_X86_64_GOTPCREL)
125 @intFromEnum(std.elf.R_X86_64.GOTPCREL)
126126 else
127 @intFromEnum(std.elf.R_X86_64.R_X86_64_PC32);
127 @intFromEnum(std.elf.R_X86_64.PC32);
128128 try atom.addReloc(elf_file, .{
129129 .r_offset = end_offset - 4,
130130 .r_info = (@as(u64, @intCast(data.sym_index)) << 32) | r_type,
......@@ -132,7 +132,7 @@ pub fn emitMir(emit: *Emit) Error!void {
132132 });
133133 } else {
134134 if (lowered_inst.encoding.mnemonic == .call and sym.flags.needs_zig_got and is_obj_or_static_lib) {
135 const r_type = @intFromEnum(std.elf.R_X86_64.R_X86_64_PC32);
135 const r_type = @intFromEnum(std.elf.R_X86_64.PC32);
136136 try atom.addReloc(elf_file, .{
137137 .r_offset = end_offset - 4,
138138 .r_info = (@as(u64, @intCast(data.sym_index)) << 32) | r_type,
......@@ -142,11 +142,11 @@ pub fn emitMir(emit: *Emit) Error!void {
142142 const r_type: u32 = if (sym.flags.needs_zig_got and !is_obj_or_static_lib)
143143 link.File.Elf.R_ZIG_GOT32
144144 else if (sym.flags.needs_got)
145 @intFromEnum(std.elf.R_X86_64.R_X86_64_GOT32)
145 @intFromEnum(std.elf.R_X86_64.GOT32)
146146 else if (sym.flags.is_tls)
147 @intFromEnum(std.elf.R_X86_64.R_X86_64_TPOFF32)
147 @intFromEnum(std.elf.R_X86_64.TPOFF32)
148148 else
149 @intFromEnum(std.elf.R_X86_64.R_X86_64_32);
149 @intFromEnum(std.elf.R_X86_64.@"32");
150150 try atom.addReloc(elf_file, .{
151151 .r_offset = end_offset - 4,
152152 .r_info = (@as(u64, @intCast(data.sym_index)) << 32) | r_type,
src/link/Elf/Atom.zig+72-72
......@@ -386,7 +386,7 @@ pub fn scanRelocsRequiresCode(self: Atom, elf_file: *Elf) bool {
386386 switch (cpu_arch) {
387387 .x86_64 => {
388388 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());
389 if (r_type == .R_X86_64_GOTTPOFF) return true;
389 if (r_type == .GOTTPOFF) return true;
390390 },
391391 else => {},
392392 }
......@@ -841,7 +841,7 @@ const x86_64 = struct {
841841 const rel = rels[i];
842842 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());
843843
844 if (r_type == .R_X86_64_NONE) continue;
844 if (r_type == .NONE) continue;
845845
846846 const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow;
847847
......@@ -874,40 +874,40 @@ const x86_64 = struct {
874874 // While traversing relocations, mark symbols that require special handling such as
875875 // pointer indirection via GOT, or a stub trampoline via PLT.
876876 switch (r_type) {
877 .R_X86_64_64 => {
877 .@"64" => {
878878 try atom.scanReloc(symbol, rel, dynAbsRelocAction(symbol, elf_file), elf_file);
879879 },
880880
881 .R_X86_64_32,
882 .R_X86_64_32S,
881 .@"32",
882 .@"32S",
883883 => {
884884 try atom.scanReloc(symbol, rel, dynAbsRelocAction(symbol, elf_file), elf_file);
885885 },
886886
887 .R_X86_64_GOT32,
888 .R_X86_64_GOTPC32,
889 .R_X86_64_GOTPC64,
890 .R_X86_64_GOTPCREL,
891 .R_X86_64_GOTPCREL64,
892 .R_X86_64_GOTPCRELX,
893 .R_X86_64_REX_GOTPCRELX,
887 .GOT32,
888 .GOTPC32,
889 .GOTPC64,
890 .GOTPCREL,
891 .GOTPCREL64,
892 .GOTPCRELX,
893 .REX_GOTPCRELX,
894894 => {
895895 symbol.flags.needs_got = true;
896896 },
897897
898 .R_X86_64_PLT32,
899 .R_X86_64_PLTOFF64,
898 .PLT32,
899 .PLTOFF64,
900900 => {
901901 if (symbol.flags.import) {
902902 symbol.flags.needs_plt = true;
903903 }
904904 },
905905
906 .R_X86_64_PC32 => {
906 .PC32 => {
907907 try atom.scanReloc(symbol, rel, pcRelocAction(symbol, elf_file), elf_file);
908908 },
909909
910 .R_X86_64_TLSGD => {
910 .TLSGD => {
911911 // TODO verify followed by appropriate relocation such as PLT32 __tls_get_addr
912912
913913 if (is_static or (!symbol.flags.import and !is_dyn_lib)) {
......@@ -922,7 +922,7 @@ const x86_64 = struct {
922922 }
923923 },
924924
925 .R_X86_64_TLSLD => {
925 .TLSLD => {
926926 // TODO verify followed by appropriate relocation such as PLT32 __tls_get_addr
927927
928928 if (is_static or !is_dyn_lib) {
......@@ -934,7 +934,7 @@ const x86_64 = struct {
934934 }
935935 },
936936
937 .R_X86_64_GOTTPOFF => {
937 .GOTTPOFF => {
938938 const should_relax = blk: {
939939 if (is_dyn_lib or symbol.flags.import) break :blk false;
940940 if (!x86_64.canRelaxGotTpOff(code.?[r_offset - 3 ..])) break :blk false;
......@@ -945,25 +945,25 @@ const x86_64 = struct {
945945 }
946946 },
947947
948 .R_X86_64_GOTPC32_TLSDESC => {
948 .GOTPC32_TLSDESC => {
949949 const should_relax = is_static or (!is_dyn_lib and !symbol.flags.import);
950950 if (!should_relax) {
951951 symbol.flags.needs_tlsdesc = true;
952952 }
953953 },
954954
955 .R_X86_64_TPOFF32,
956 .R_X86_64_TPOFF64,
955 .TPOFF32,
956 .TPOFF64,
957957 => {
958958 if (is_dyn_lib) try atom.reportPicError(symbol, rel, elf_file);
959959 },
960960
961 .R_X86_64_GOTOFF64,
962 .R_X86_64_DTPOFF32,
963 .R_X86_64_DTPOFF64,
964 .R_X86_64_SIZE32,
965 .R_X86_64_SIZE64,
966 .R_X86_64_TLSDESC_CALL,
961 .GOTOFF64,
962 .DTPOFF32,
963 .DTPOFF64,
964 .SIZE32,
965 .SIZE64,
966 .TLSDESC_CALL,
967967 => {},
968968
969969 else => |x| switch (@intFromEnum(x)) {
......@@ -990,7 +990,7 @@ const x86_64 = struct {
990990 while (i < rels.len) : (i += 1) {
991991 const rel = rels[i];
992992 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());
993 if (r_type == .R_X86_64_NONE) continue;
993 if (r_type == .NONE) continue;
994994
995995 const target = switch (file_ptr) {
996996 .zig_object => |x| elf_file.symbol(x.symbol(rel.r_sym())),
......@@ -1040,9 +1040,9 @@ const x86_64 = struct {
10401040 try stream.seekTo(r_offset);
10411041
10421042 switch (r_type) {
1043 .R_X86_64_NONE => unreachable,
1043 .NONE => unreachable,
10441044
1045 .R_X86_64_64 => {
1045 .@"64" => {
10461046 try atom.resolveDynAbsReloc(
10471047 target,
10481048 rel,
......@@ -1052,15 +1052,15 @@ const x86_64 = struct {
10521052 );
10531053 },
10541054
1055 .R_X86_64_PLT32,
1056 .R_X86_64_PC32,
1055 .PLT32,
1056 .PC32,
10571057 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little),
10581058
1059 .R_X86_64_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little),
1060 .R_X86_64_GOTPC32 => try cwriter.writeInt(i32, @as(i32, @intCast(GOT + A - P)), .little),
1061 .R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A - P, .little),
1059 .GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little),
1060 .GOTPC32 => try cwriter.writeInt(i32, @as(i32, @intCast(GOT + A - P)), .little),
1061 .GOTPC64 => try cwriter.writeInt(i64, GOT + A - P, .little),
10621062
1063 .R_X86_64_GOTPCRELX => {
1063 .GOTPCRELX => {
10641064 if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: {
10651065 x86_64.relaxGotpcrelx(code[r_offset - 2 ..]) catch break :blk;
10661066 try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little);
......@@ -1069,7 +1069,7 @@ const x86_64 = struct {
10691069 try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little);
10701070 },
10711071
1072 .R_X86_64_REX_GOTPCRELX => {
1072 .REX_GOTPCRELX => {
10731073 if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: {
10741074 x86_64.relaxRexGotpcrelx(code[r_offset - 3 ..]) catch break :blk;
10751075 try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little);
......@@ -1078,16 +1078,16 @@ const x86_64 = struct {
10781078 try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little);
10791079 },
10801080
1081 .R_X86_64_32 => try cwriter.writeInt(u32, @as(u32, @truncate(@as(u64, @intCast(S + A)))), .little),
1082 .R_X86_64_32S => try cwriter.writeInt(i32, @as(i32, @truncate(S + A)), .little),
1081 .@"32" => try cwriter.writeInt(u32, @as(u32, @truncate(@as(u64, @intCast(S + A)))), .little),
1082 .@"32S" => try cwriter.writeInt(i32, @as(i32, @truncate(S + A)), .little),
10831083
1084 .R_X86_64_TPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - TP)), .little),
1085 .R_X86_64_TPOFF64 => try cwriter.writeInt(i64, S + A - TP, .little),
1084 .TPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - TP)), .little),
1085 .TPOFF64 => try cwriter.writeInt(i64, S + A - TP, .little),
10861086
1087 .R_X86_64_DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - DTP)), .little),
1088 .R_X86_64_DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .little),
1087 .DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - DTP)), .little),
1088 .DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .little),
10891089
1090 .R_X86_64_TLSGD => {
1090 .TLSGD => {
10911091 if (target.flags.has_tlsgd) {
10921092 const S_ = @as(i64, @intCast(target.tlsGdAddress(elf_file)));
10931093 try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little);
......@@ -1107,7 +1107,7 @@ const x86_64 = struct {
11071107 }
11081108 },
11091109
1110 .R_X86_64_TLSLD => {
1110 .TLSLD => {
11111111 if (elf_file.got.tlsld_index) |entry_index| {
11121112 const tlsld_entry = elf_file.got.entries.items[entry_index];
11131113 const S_ = @as(i64, @intCast(tlsld_entry.address(elf_file)));
......@@ -1124,7 +1124,7 @@ const x86_64 = struct {
11241124 }
11251125 },
11261126
1127 .R_X86_64_GOTPC32_TLSDESC => {
1127 .GOTPC32_TLSDESC => {
11281128 if (target.flags.has_tlsdesc) {
11291129 const S_ = @as(i64, @intCast(target.tlsDescAddress(elf_file)));
11301130 try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little);
......@@ -1134,12 +1134,12 @@ const x86_64 = struct {
11341134 }
11351135 },
11361136
1137 .R_X86_64_TLSDESC_CALL => if (!target.flags.has_tlsdesc) {
1137 .TLSDESC_CALL => if (!target.flags.has_tlsdesc) {
11381138 // call -> nop
11391139 try cwriter.writeAll(&.{ 0x66, 0x90 });
11401140 },
11411141
1142 .R_X86_64_GOTTPOFF => {
1142 .GOTTPOFF => {
11431143 if (target.flags.has_gottp) {
11441144 const S_ = @as(i64, @intCast(target.gotTpAddress(elf_file)));
11451145 try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little);
......@@ -1149,7 +1149,7 @@ const x86_64 = struct {
11491149 }
11501150 },
11511151
1152 .R_X86_64_GOT32 => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A)), .little),
1152 .GOT32 => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A)), .little),
11531153
11541154 else => |x| switch (@intFromEnum(x)) {
11551155 // Zig custom relocations
......@@ -1172,7 +1172,7 @@ const x86_64 = struct {
11721172 while (i < rels.len) : (i += 1) {
11731173 const rel = rels[i];
11741174 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());
1175 if (r_type == .R_X86_64_NONE) continue;
1175 if (r_type == .NONE) continue;
11761176
11771177 const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow;
11781178
......@@ -1229,21 +1229,21 @@ const x86_64 = struct {
12291229 try stream.seekTo(r_offset);
12301230
12311231 switch (r_type) {
1232 .R_X86_64_NONE => unreachable,
1233 .R_X86_64_8 => try cwriter.writeInt(u8, @as(u8, @bitCast(@as(i8, @intCast(S + A)))), .little),
1234 .R_X86_64_16 => try cwriter.writeInt(u16, @as(u16, @bitCast(@as(i16, @intCast(S + A)))), .little),
1235 .R_X86_64_32 => try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(S + A)))), .little),
1236 .R_X86_64_32S => try cwriter.writeInt(i32, @as(i32, @intCast(S + A)), .little),
1237 .R_X86_64_64 => try cwriter.writeInt(i64, S + A, .little),
1238 .R_X86_64_DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - DTP)), .little),
1239 .R_X86_64_DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .little),
1240 .R_X86_64_GOTOFF64 => try cwriter.writeInt(i64, S + A - GOT, .little),
1241 .R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A, .little),
1242 .R_X86_64_SIZE32 => {
1232 .NONE => unreachable,
1233 .@"8" => try cwriter.writeInt(u8, @as(u8, @bitCast(@as(i8, @intCast(S + A)))), .little),
1234 .@"16" => try cwriter.writeInt(u16, @as(u16, @bitCast(@as(i16, @intCast(S + A)))), .little),
1235 .@"32" => try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(S + A)))), .little),
1236 .@"32S" => try cwriter.writeInt(i32, @as(i32, @intCast(S + A)), .little),
1237 .@"64" => try cwriter.writeInt(i64, S + A, .little),
1238 .DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - DTP)), .little),
1239 .DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .little),
1240 .GOTOFF64 => try cwriter.writeInt(i64, S + A - GOT, .little),
1241 .GOTPC64 => try cwriter.writeInt(i64, GOT + A, .little),
1242 .SIZE32 => {
12431243 const size = @as(i64, @intCast(target.elfSym(elf_file).st_size));
12441244 try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(size + A)))), .little);
12451245 },
1246 .R_X86_64_SIZE64 => {
1246 .SIZE64 => {
12471247 const size = @as(i64, @intCast(target.elfSym(elf_file).st_size));
12481248 try cwriter.writeInt(i64, @as(i64, @intCast(size + A)), .little);
12491249 },
......@@ -1293,8 +1293,8 @@ const x86_64 = struct {
12931293 const writer = stream.writer();
12941294 const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type());
12951295 switch (rel) {
1296 .R_X86_64_PC32,
1297 .R_X86_64_PLT32,
1296 .PC32,
1297 .PLT32,
12981298 => {
12991299 var insts = [_]u8{
13001300 0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax
......@@ -1331,8 +1331,8 @@ const x86_64 = struct {
13311331 const writer = stream.writer();
13321332 const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type());
13331333 switch (rel) {
1334 .R_X86_64_PC32,
1335 .R_X86_64_PLT32,
1334 .PC32,
1335 .PLT32,
13361336 => {
13371337 var insts = [_]u8{
13381338 0x31, 0xc0, // xor %eax, %eax
......@@ -1344,8 +1344,8 @@ const x86_64 = struct {
13441344 try writer.writeAll(&insts);
13451345 },
13461346
1347 .R_X86_64_GOTPCREL,
1348 .R_X86_64_GOTPCRELX,
1347 .GOTPCREL,
1348 .GOTPCRELX,
13491349 => {
13501350 var insts = [_]u8{
13511351 0x31, 0xc0, // xor %eax, %eax
......@@ -1431,10 +1431,10 @@ const x86_64 = struct {
14311431 const writer = stream.writer();
14321432 const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type());
14331433 switch (rel) {
1434 .R_X86_64_PC32,
1435 .R_X86_64_PLT32,
1436 .R_X86_64_GOTPCREL,
1437 .R_X86_64_GOTPCRELX,
1434 .PC32,
1435 .PLT32,
1436 .GOTPCREL,
1437 .GOTPCRELX,
14381438 => {
14391439 var insts = [_]u8{
14401440 0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax
src/link/Elf/eh_frame.zig+4-4
......@@ -543,10 +543,10 @@ const x86_64 = struct {
543543 fn resolveReloc(rel: elf.Elf64_Rela, source: i64, target: i64, data: []u8) void {
544544 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());
545545 switch (r_type) {
546 .R_X86_64_32 => std.mem.writeInt(i32, data[0..4], @as(i32, @truncate(target)), .little),
547 .R_X86_64_64 => std.mem.writeInt(i64, data[0..8], target, .little),
548 .R_X86_64_PC32 => std.mem.writeInt(i32, data[0..4], @as(i32, @intCast(target - source)), .little),
549 .R_X86_64_PC64 => std.mem.writeInt(i64, data[0..8], target - source, .little),
546 .@"32" => std.mem.writeInt(i32, data[0..4], @as(i32, @truncate(target)), .little),
547 .@"64" => std.mem.writeInt(i64, data[0..8], target, .little),
548 .PC32 => std.mem.writeInt(i32, data[0..4], @as(i32, @intCast(target - source)), .little),
549 .PC64 => std.mem.writeInt(i64, data[0..8], target - source, .little),
550550 else => unreachable,
551551 }
552552 }
src/link/Elf/relocation.zig+36-37
......@@ -30,41 +30,41 @@ fn Table(comptime len: comptime_int, comptime RelType: type, comptime mapping: [
3030}
3131
3232const x86_64_relocs = Table(10, elf.R_X86_64, .{
33 .{ .abs, .R_X86_64_64 },
34 .{ .copy, .R_X86_64_COPY },
35 .{ .rel, .R_X86_64_RELATIVE },
36 .{ .irel, .R_X86_64_IRELATIVE },
37 .{ .glob_dat, .R_X86_64_GLOB_DAT },
38 .{ .jump_slot, .R_X86_64_JUMP_SLOT },
39 .{ .dtpmod, .R_X86_64_DTPMOD64 },
40 .{ .dtpoff, .R_X86_64_DTPOFF64 },
41 .{ .tpoff, .R_X86_64_TPOFF64 },
42 .{ .tlsdesc, .R_X86_64_TLSDESC },
33 .{ .abs, .@"64" },
34 .{ .copy, .COPY },
35 .{ .rel, .RELATIVE },
36 .{ .irel, .IRELATIVE },
37 .{ .glob_dat, .GLOB_DAT },
38 .{ .jump_slot, .JUMP_SLOT },
39 .{ .dtpmod, .DTPMOD64 },
40 .{ .dtpoff, .DTPOFF64 },
41 .{ .tpoff, .TPOFF64 },
42 .{ .tlsdesc, .TLSDESC },
4343});
4444
4545const aarch64_relocs = Table(10, elf.R_AARCH64, .{
46 .{ .abs, .R_AARCH64_ABS64 },
47 .{ .copy, .R_AARCH64_COPY },
48 .{ .rel, .R_AARCH64_RELATIVE },
49 .{ .irel, .R_AARCH64_IRELATIVE },
50 .{ .glob_dat, .R_AARCH64_GLOB_DAT },
51 .{ .jump_slot, .R_AARCH64_JUMP_SLOT },
52 .{ .dtpmod, .R_AARCH64_TLS_DTPMOD },
53 .{ .dtpoff, .R_AARCH64_TLS_DTPREL },
54 .{ .tpoff, .R_AARCH64_TLS_TPREL },
55 .{ .tlsdesc, .R_AARCH64_TLSDESC },
46 .{ .abs, .ABS64 },
47 .{ .copy, .COPY },
48 .{ .rel, .RELATIVE },
49 .{ .irel, .IRELATIVE },
50 .{ .glob_dat, .GLOB_DAT },
51 .{ .jump_slot, .JUMP_SLOT },
52 .{ .dtpmod, .TLS_DTPMOD },
53 .{ .dtpoff, .TLS_DTPREL },
54 .{ .tpoff, .TLS_TPREL },
55 .{ .tlsdesc, .TLSDESC },
5656});
5757
5858const riscv64_relocs = Table(9, elf.R_RISCV, .{
59 .{ .abs, .R_RISCV_64 },
60 .{ .copy, .R_RISCV_COPY },
61 .{ .rel, .R_RISCV_RELATIVE },
62 .{ .irel, .R_RISCV_IRELATIVE },
63 .{ .jump_slot, .R_RISCV_JUMP_SLOT },
64 .{ .dtpmod, .R_RISCV_TLS_DTPMOD64 },
65 .{ .dtpoff, .R_RISCV_TLS_DTPREL64 },
66 .{ .tpoff, .R_RISCV_TLS_TPREL64 },
67 .{ .tlsdesc, .R_RISCV_TLSDESC },
59 .{ .abs, .@"64" },
60 .{ .copy, .COPY },
61 .{ .rel, .RELATIVE },
62 .{ .irel, .IRELATIVE },
63 .{ .jump_slot, .JUMP_SLOT },
64 .{ .dtpmod, .TLS_DTPMOD64 },
65 .{ .dtpoff, .TLS_DTPREL64 },
66 .{ .tpoff, .TLS_TPREL64 },
67 .{ .tlsdesc, .TLSDESC },
6868});
6969
7070pub fn decode(r_type: u32, cpu_arch: std.Target.Cpu.Arch) ?Kind {
......@@ -106,17 +106,16 @@ fn formatRelocType(
106106 _ = unused_fmt_string;
107107 _ = options;
108108 const r_type = ctx.r_type;
109 const str = switch (r_type) {
110 Elf.R_ZIG_GOT32 => "R_ZIG_GOT32",
111 Elf.R_ZIG_GOTPCREL => "R_ZIG_GOTPCREL",
109 switch (r_type) {
110 Elf.R_ZIG_GOT32 => try writer.writeAll("R_ZIG_GOT32"),
111 Elf.R_ZIG_GOTPCREL => try writer.writeAll("R_ZIG_GOTPCREL"),
112112 else => switch (ctx.cpu_arch) {
113 .x86_64 => @tagName(@as(elf.R_X86_64, @enumFromInt(r_type))),
114 .aarch64 => @tagName(@as(elf.R_AARCH64, @enumFromInt(r_type))),
115 .riscv64 => @tagName(@as(elf.R_RISCV, @enumFromInt(r_type))),
113 .x86_64 => try writer.print("R_X86_64_{s}", .{@tagName(@as(elf.R_X86_64, @enumFromInt(r_type)))}),
114 .aarch64 => try writer.print("R_AARCH64_{s}", .{@tagName(@as(elf.R_AARCH64, @enumFromInt(r_type)))}),
115 .riscv64 => try writer.print("R_RISCV_{s}", .{@tagName(@as(elf.R_RISCV, @enumFromInt(r_type)))}),
116116 else => unreachable,
117117 },
118 };
119 try writer.print("{s}", .{str});
118 }
120119}
121120
122121const assert = std.debug.assert;