abi.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. // Copyright 2022 The Gc Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package gc // import "modernc.org/gc/v3"
  5. import (
  6. "encoding/binary"
  7. "fmt"
  8. )
  9. var (
  10. byteOrders = map[string]binary.ByteOrder{
  11. "386": binary.LittleEndian,
  12. "amd64": binary.LittleEndian,
  13. "arm": binary.LittleEndian,
  14. "arm64": binary.LittleEndian,
  15. "loong64": binary.LittleEndian,
  16. "ppc64le": binary.LittleEndian,
  17. "riscv64": binary.LittleEndian,
  18. "s390x": binary.BigEndian,
  19. }
  20. abiTypes = map[[2]string]map[Kind]ABIType{
  21. // go1.19.1
  22. {"freebsd", "386"}: {
  23. Bool: {1, 1, 1},
  24. Chan: {4, 4, 4},
  25. Complex128: {16, 4, 4},
  26. Complex64: {8, 4, 4},
  27. Float32: {4, 4, 4},
  28. Float64: {8, 4, 4},
  29. Function: {4, 4, 4},
  30. Int: {4, 4, 4},
  31. Int16: {2, 2, 2},
  32. Int32: {4, 4, 4},
  33. Int64: {8, 4, 4},
  34. Int8: {1, 1, 1},
  35. Interface: {8, 4, 4},
  36. Map: {4, 4, 4},
  37. Pointer: {4, 4, 4},
  38. Slice: {12, 4, 4},
  39. String: {8, 4, 4},
  40. Uint: {4, 4, 4},
  41. Uint16: {2, 2, 2},
  42. Uint32: {4, 4, 4},
  43. Uint64: {8, 4, 4},
  44. Uint8: {1, 1, 1},
  45. Uintptr: {4, 4, 4},
  46. UnsafePointer: {4, 4, 4},
  47. },
  48. // go1.19.1
  49. {"freebsd", "amd64"}: {
  50. Bool: {1, 1, 1},
  51. Chan: {8, 8, 8},
  52. Complex128: {16, 8, 8},
  53. Complex64: {8, 4, 4},
  54. Float32: {4, 4, 4},
  55. Float64: {8, 8, 8},
  56. Function: {8, 8, 8},
  57. Int: {8, 8, 8},
  58. Int16: {2, 2, 2},
  59. Int32: {4, 4, 4},
  60. Int64: {8, 8, 8},
  61. Int8: {1, 1, 1},
  62. Interface: {16, 8, 8},
  63. Map: {8, 8, 8},
  64. Pointer: {8, 8, 8},
  65. Slice: {24, 8, 8},
  66. String: {16, 8, 8},
  67. Uint: {8, 8, 8},
  68. Uint16: {2, 2, 2},
  69. Uint32: {4, 4, 4},
  70. Uint64: {8, 8, 8},
  71. Uint8: {1, 1, 1},
  72. Uintptr: {8, 8, 8},
  73. UnsafePointer: {8, 8, 8},
  74. },
  75. // go1.18.5
  76. {"freebsd", "arm"}: {
  77. Bool: {1, 1, 1},
  78. Chan: {4, 4, 4},
  79. Complex128: {16, 4, 4},
  80. Complex64: {8, 4, 4},
  81. Float32: {4, 4, 4},
  82. Float64: {8, 4, 4},
  83. Function: {4, 4, 4},
  84. Int: {4, 4, 4},
  85. Int16: {2, 2, 2},
  86. Int32: {4, 4, 4},
  87. Int64: {8, 4, 4},
  88. Int8: {1, 1, 1},
  89. Interface: {8, 4, 4},
  90. Map: {4, 4, 4},
  91. Pointer: {4, 4, 4},
  92. Slice: {12, 4, 4},
  93. String: {8, 4, 4},
  94. Uint: {4, 4, 4},
  95. Uint16: {2, 2, 2},
  96. Uint32: {4, 4, 4},
  97. Uint64: {8, 4, 4},
  98. Uint8: {1, 1, 1},
  99. Uintptr: {4, 4, 4},
  100. UnsafePointer: {4, 4, 4},
  101. },
  102. // go1.19
  103. {"freebsd", "arm64"}: {
  104. Bool: {1, 1, 1},
  105. Chan: {8, 8, 8},
  106. Complex128: {16, 8, 8},
  107. Complex64: {8, 4, 4},
  108. Float32: {4, 4, 4},
  109. Float64: {8, 8, 8},
  110. Function: {8, 8, 8},
  111. Int: {8, 8, 8},
  112. Int16: {2, 2, 2},
  113. Int32: {4, 4, 4},
  114. Int64: {8, 8, 8},
  115. Int8: {1, 1, 1},
  116. Interface: {16, 8, 8},
  117. Map: {8, 8, 8},
  118. Pointer: {8, 8, 8},
  119. Slice: {24, 8, 8},
  120. String: {16, 8, 8},
  121. Uint: {8, 8, 8},
  122. Uint16: {2, 2, 2},
  123. Uint32: {4, 4, 4},
  124. Uint64: {8, 8, 8},
  125. Uint8: {1, 1, 1},
  126. Uintptr: {8, 8, 8},
  127. UnsafePointer: {8, 8, 8},
  128. },
  129. // go1.19.1
  130. {"darwin", "amd64"}: {
  131. Bool: {1, 1, 1},
  132. Chan: {8, 8, 8},
  133. Complex128: {16, 8, 8},
  134. Complex64: {8, 4, 4},
  135. Float32: {4, 4, 4},
  136. Float64: {8, 8, 8},
  137. Function: {8, 8, 8},
  138. Int: {8, 8, 8},
  139. Int16: {2, 2, 2},
  140. Int32: {4, 4, 4},
  141. Int64: {8, 8, 8},
  142. Int8: {1, 1, 1},
  143. Interface: {16, 8, 8},
  144. Map: {8, 8, 8},
  145. Pointer: {8, 8, 8},
  146. Slice: {24, 8, 8},
  147. String: {16, 8, 8},
  148. Uint: {8, 8, 8},
  149. Uint16: {2, 2, 2},
  150. Uint32: {4, 4, 4},
  151. Uint64: {8, 8, 8},
  152. Uint8: {1, 1, 1},
  153. Uintptr: {8, 8, 8},
  154. UnsafePointer: {8, 8, 8},
  155. },
  156. // go1.19.1
  157. {"darwin", "arm64"}: {
  158. Bool: {1, 1, 1},
  159. Chan: {8, 8, 8},
  160. Complex128: {16, 8, 8},
  161. Complex64: {8, 4, 4},
  162. Float32: {4, 4, 4},
  163. Float64: {8, 8, 8},
  164. Function: {8, 8, 8},
  165. Int: {8, 8, 8},
  166. Int16: {2, 2, 2},
  167. Int32: {4, 4, 4},
  168. Int64: {8, 8, 8},
  169. Int8: {1, 1, 1},
  170. Interface: {16, 8, 8},
  171. Map: {8, 8, 8},
  172. Pointer: {8, 8, 8},
  173. Slice: {24, 8, 8},
  174. String: {16, 8, 8},
  175. Uint: {8, 8, 8},
  176. Uint16: {2, 2, 2},
  177. Uint32: {4, 4, 4},
  178. Uint64: {8, 8, 8},
  179. Uint8: {1, 1, 1},
  180. Uintptr: {8, 8, 8},
  181. UnsafePointer: {8, 8, 8},
  182. },
  183. // go1.19.1
  184. {"linux", "386"}: {
  185. Bool: {1, 1, 1},
  186. Chan: {4, 4, 4},
  187. Complex128: {16, 4, 4},
  188. Complex64: {8, 4, 4},
  189. Float32: {4, 4, 4},
  190. Float64: {8, 4, 4},
  191. Function: {4, 4, 4},
  192. Int: {4, 4, 4},
  193. Int16: {2, 2, 2},
  194. Int32: {4, 4, 4},
  195. Int64: {8, 4, 4},
  196. Int8: {1, 1, 1},
  197. Interface: {8, 4, 4},
  198. Map: {4, 4, 4},
  199. Pointer: {4, 4, 4},
  200. Slice: {12, 4, 4},
  201. String: {8, 4, 4},
  202. Uint: {4, 4, 4},
  203. Uint16: {2, 2, 2},
  204. Uint32: {4, 4, 4},
  205. Uint64: {8, 4, 4},
  206. Uint8: {1, 1, 1},
  207. Uintptr: {4, 4, 4},
  208. UnsafePointer: {4, 4, 4},
  209. },
  210. // go1.19.1
  211. {"linux", "amd64"}: {
  212. Bool: {1, 1, 1},
  213. Chan: {8, 8, 8},
  214. Complex128: {16, 8, 8},
  215. Complex64: {8, 4, 4},
  216. Float32: {4, 4, 4},
  217. Float64: {8, 8, 8},
  218. Function: {8, 8, 8},
  219. Int: {8, 8, 8},
  220. Int16: {2, 2, 2},
  221. Int32: {4, 4, 4},
  222. Int64: {8, 8, 8},
  223. Int8: {1, 1, 1},
  224. Interface: {16, 8, 8},
  225. Map: {8, 8, 8},
  226. Pointer: {8, 8, 8},
  227. Slice: {24, 8, 8},
  228. String: {16, 8, 8},
  229. Uint: {8, 8, 8},
  230. Uint16: {2, 2, 2},
  231. Uint32: {4, 4, 4},
  232. Uint64: {8, 8, 8},
  233. Uint8: {1, 1, 1},
  234. Uintptr: {8, 8, 8},
  235. UnsafePointer: {8, 8, 8},
  236. },
  237. // go1.19.1
  238. {"linux", "arm"}: {
  239. Bool: {1, 1, 1},
  240. Chan: {4, 4, 4},
  241. Complex128: {16, 4, 4},
  242. Complex64: {8, 4, 4},
  243. Float32: {4, 4, 4},
  244. Float64: {8, 4, 4},
  245. Function: {4, 4, 4},
  246. Int: {4, 4, 4},
  247. Int16: {2, 2, 2},
  248. Int32: {4, 4, 4},
  249. Int64: {8, 4, 4},
  250. Int8: {1, 1, 1},
  251. Interface: {8, 4, 4},
  252. Map: {4, 4, 4},
  253. Pointer: {4, 4, 4},
  254. Slice: {12, 4, 4},
  255. String: {8, 4, 4},
  256. Uint: {4, 4, 4},
  257. Uint16: {2, 2, 2},
  258. Uint32: {4, 4, 4},
  259. Uint64: {8, 4, 4},
  260. Uint8: {1, 1, 1},
  261. Uintptr: {4, 4, 4},
  262. UnsafePointer: {4, 4, 4},
  263. },
  264. // go1.19.1
  265. {"linux", "arm64"}: {
  266. Bool: {1, 1, 1},
  267. Chan: {8, 8, 8},
  268. Complex128: {16, 8, 8},
  269. Complex64: {8, 4, 4},
  270. Float32: {4, 4, 4},
  271. Float64: {8, 8, 8},
  272. Function: {8, 8, 8},
  273. Int: {8, 8, 8},
  274. Int16: {2, 2, 2},
  275. Int32: {4, 4, 4},
  276. Int64: {8, 8, 8},
  277. Int8: {1, 1, 1},
  278. Interface: {16, 8, 8},
  279. Map: {8, 8, 8},
  280. Pointer: {8, 8, 8},
  281. Slice: {24, 8, 8},
  282. String: {16, 8, 8},
  283. Uint: {8, 8, 8},
  284. Uint16: {2, 2, 2},
  285. Uint32: {4, 4, 4},
  286. Uint64: {8, 8, 8},
  287. Uint8: {1, 1, 1},
  288. Uintptr: {8, 8, 8},
  289. UnsafePointer: {8, 8, 8},
  290. },
  291. // go1.19.1
  292. {"linux", "s390x"}: {
  293. Bool: {1, 1, 1},
  294. Chan: {8, 8, 8},
  295. Complex128: {16, 8, 8},
  296. Complex64: {8, 4, 4},
  297. Float32: {4, 4, 4},
  298. Float64: {8, 8, 8},
  299. Function: {8, 8, 8},
  300. Int: {8, 8, 8},
  301. Int16: {2, 2, 2},
  302. Int32: {4, 4, 4},
  303. Int64: {8, 8, 8},
  304. Int8: {1, 1, 1},
  305. Interface: {16, 8, 8},
  306. Map: {8, 8, 8},
  307. Pointer: {8, 8, 8},
  308. Slice: {24, 8, 8},
  309. String: {16, 8, 8},
  310. Uint: {8, 8, 8},
  311. Uint16: {2, 2, 2},
  312. Uint32: {4, 4, 4},
  313. Uint64: {8, 8, 8},
  314. Uint8: {1, 1, 1},
  315. Uintptr: {8, 8, 8},
  316. UnsafePointer: {8, 8, 8},
  317. },
  318. // go1.19.1
  319. {"linux", "ppc64le"}: {
  320. Bool: {1, 1, 1},
  321. Chan: {8, 8, 8},
  322. Complex128: {16, 8, 8},
  323. Complex64: {8, 4, 4},
  324. Float32: {4, 4, 4},
  325. Float64: {8, 8, 8},
  326. Function: {8, 8, 8},
  327. Int: {8, 8, 8},
  328. Int16: {2, 2, 2},
  329. Int32: {4, 4, 4},
  330. Int64: {8, 8, 8},
  331. Int8: {1, 1, 1},
  332. Interface: {16, 8, 8},
  333. Map: {8, 8, 8},
  334. Pointer: {8, 8, 8},
  335. Slice: {24, 8, 8},
  336. String: {16, 8, 8},
  337. Uint: {8, 8, 8},
  338. Uint16: {2, 2, 2},
  339. Uint32: {4, 4, 4},
  340. Uint64: {8, 8, 8},
  341. Uint8: {1, 1, 1},
  342. Uintptr: {8, 8, 8},
  343. UnsafePointer: {8, 8, 8},
  344. },
  345. // go1.19.1
  346. {"linux", "riscv64"}: {
  347. Bool: {1, 1, 1},
  348. Chan: {8, 8, 8},
  349. Complex128: {16, 8, 8},
  350. Complex64: {8, 4, 4},
  351. Float32: {4, 4, 4},
  352. Float64: {8, 8, 8},
  353. Function: {8, 8, 8},
  354. Int: {8, 8, 8},
  355. Int16: {2, 2, 2},
  356. Int32: {4, 4, 4},
  357. Int64: {8, 8, 8},
  358. Int8: {1, 1, 1},
  359. Interface: {16, 8, 8},
  360. Map: {8, 8, 8},
  361. Pointer: {8, 8, 8},
  362. Slice: {24, 8, 8},
  363. String: {16, 8, 8},
  364. Uint: {8, 8, 8},
  365. Uint16: {2, 2, 2},
  366. Uint32: {4, 4, 4},
  367. Uint64: {8, 8, 8},
  368. Uint8: {1, 1, 1},
  369. Uintptr: {8, 8, 8},
  370. UnsafePointer: {8, 8, 8},
  371. },
  372. // go1.21.5
  373. {"linux", "loong64"}: {
  374. Bool: {1, 1, 1},
  375. Chan: {8, 8, 8},
  376. Complex128: {16, 8, 8},
  377. Complex64: {8, 4, 4},
  378. Float32: {4, 4, 4},
  379. Float64: {8, 8, 8},
  380. Function: {8, 8, 8},
  381. Int: {8, 8, 8},
  382. Int16: {2, 2, 2},
  383. Int32: {4, 4, 4},
  384. Int64: {8, 8, 8},
  385. Int8: {1, 1, 1},
  386. Interface: {16, 8, 8},
  387. Map: {8, 8, 8},
  388. Pointer: {8, 8, 8},
  389. Slice: {24, 8, 8},
  390. String: {16, 8, 8},
  391. Uint: {8, 8, 8},
  392. Uint16: {2, 2, 2},
  393. Uint32: {4, 4, 4},
  394. Uint64: {8, 8, 8},
  395. Uint8: {1, 1, 1},
  396. Uintptr: {8, 8, 8},
  397. UnsafePointer: {8, 8, 8},
  398. },
  399. // go1.18.3
  400. {"netbsd", "386"}: {
  401. Bool: {1, 1, 1},
  402. Chan: {4, 4, 4},
  403. Complex128: {16, 4, 4},
  404. Complex64: {8, 4, 4},
  405. Float32: {4, 4, 4},
  406. Float64: {8, 4, 4},
  407. Function: {4, 4, 4},
  408. Int: {4, 4, 4},
  409. Int16: {2, 2, 2},
  410. Int32: {4, 4, 4},
  411. Int64: {8, 4, 4},
  412. Int8: {1, 1, 1},
  413. Interface: {8, 4, 4},
  414. Map: {4, 4, 4},
  415. Pointer: {4, 4, 4},
  416. Slice: {12, 4, 4},
  417. String: {8, 4, 4},
  418. Uint: {4, 4, 4},
  419. Uint16: {2, 2, 2},
  420. Uint32: {4, 4, 4},
  421. Uint64: {8, 4, 4},
  422. Uint8: {1, 1, 1},
  423. Uintptr: {4, 4, 4},
  424. UnsafePointer: {4, 4, 4},
  425. },
  426. // go1.18.3
  427. {"netbsd", "amd64"}: {
  428. Bool: {1, 1, 1},
  429. Chan: {8, 8, 8},
  430. Complex128: {16, 8, 8},
  431. Complex64: {8, 4, 4},
  432. Float32: {4, 4, 4},
  433. Float64: {8, 8, 8},
  434. Function: {8, 8, 8},
  435. Int: {8, 8, 8},
  436. Int16: {2, 2, 2},
  437. Int32: {4, 4, 4},
  438. Int64: {8, 8, 8},
  439. Int8: {1, 1, 1},
  440. Interface: {16, 8, 8},
  441. Map: {8, 8, 8},
  442. Pointer: {8, 8, 8},
  443. Slice: {24, 8, 8},
  444. String: {16, 8, 8},
  445. Uint: {8, 8, 8},
  446. Uint16: {2, 2, 2},
  447. Uint32: {4, 4, 4},
  448. Uint64: {8, 8, 8},
  449. Uint8: {1, 1, 1},
  450. Uintptr: {8, 8, 8},
  451. UnsafePointer: {8, 8, 8},
  452. },
  453. // go1.18.3
  454. {"netbsd", "arm"}: {
  455. Bool: {1, 1, 1},
  456. Chan: {4, 4, 4},
  457. Complex128: {16, 4, 4},
  458. Complex64: {8, 4, 4},
  459. Float32: {4, 4, 4},
  460. Float64: {8, 4, 4},
  461. Function: {4, 4, 4},
  462. Int: {4, 4, 4},
  463. Int16: {2, 2, 2},
  464. Int32: {4, 4, 4},
  465. Int64: {8, 4, 4},
  466. Int8: {1, 1, 1},
  467. Interface: {8, 4, 4},
  468. Map: {4, 4, 4},
  469. Pointer: {4, 4, 4},
  470. Slice: {12, 4, 4},
  471. String: {8, 4, 4},
  472. Uint: {4, 4, 4},
  473. Uint16: {2, 2, 2},
  474. Uint32: {4, 4, 4},
  475. Uint64: {8, 4, 4},
  476. Uint8: {1, 1, 1},
  477. Uintptr: {4, 4, 4},
  478. UnsafePointer: {4, 4, 4},
  479. },
  480. // go1.19
  481. {"openbsd", "amd64"}: {
  482. Bool: {1, 1, 1},
  483. Chan: {8, 8, 8},
  484. Complex128: {16, 8, 8},
  485. Complex64: {8, 4, 4},
  486. Float32: {4, 4, 4},
  487. Float64: {8, 8, 8},
  488. Function: {8, 8, 8},
  489. Int: {8, 8, 8},
  490. Int16: {2, 2, 2},
  491. Int32: {4, 4, 4},
  492. Int64: {8, 8, 8},
  493. Int8: {1, 1, 1},
  494. Interface: {16, 8, 8},
  495. Map: {8, 8, 8},
  496. Pointer: {8, 8, 8},
  497. Slice: {24, 8, 8},
  498. String: {16, 8, 8},
  499. Uint: {8, 8, 8},
  500. Uint16: {2, 2, 2},
  501. Uint32: {4, 4, 4},
  502. Uint64: {8, 8, 8},
  503. Uint8: {1, 1, 1},
  504. Uintptr: {8, 8, 8},
  505. UnsafePointer: {8, 8, 8},
  506. },
  507. // go1.19
  508. {"openbsd", "arm64"}: {
  509. Bool: {1, 1, 1},
  510. Chan: {8, 8, 8},
  511. Complex128: {16, 8, 8},
  512. Complex64: {8, 4, 4},
  513. Float32: {4, 4, 4},
  514. Float64: {8, 8, 8},
  515. Function: {8, 8, 8},
  516. Int: {8, 8, 8},
  517. Int16: {2, 2, 2},
  518. Int32: {4, 4, 4},
  519. Int64: {8, 8, 8},
  520. Int8: {1, 1, 1},
  521. Interface: {16, 8, 8},
  522. Map: {8, 8, 8},
  523. Pointer: {8, 8, 8},
  524. Slice: {24, 8, 8},
  525. String: {16, 8, 8},
  526. Uint: {8, 8, 8},
  527. Uint16: {2, 2, 2},
  528. Uint32: {4, 4, 4},
  529. Uint64: {8, 8, 8},
  530. Uint8: {1, 1, 1},
  531. Uintptr: {8, 8, 8},
  532. UnsafePointer: {8, 8, 8},
  533. },
  534. // go1.19
  535. {"openbsd", "386"}: {
  536. Bool: {1, 1, 1},
  537. Chan: {4, 4, 4},
  538. Complex128: {16, 4, 4},
  539. Complex64: {8, 4, 4},
  540. Float32: {4, 4, 4},
  541. Float64: {8, 4, 4},
  542. Function: {4, 4, 4},
  543. Int: {4, 4, 4},
  544. Int16: {2, 2, 2},
  545. Int32: {4, 4, 4},
  546. Int64: {8, 4, 4},
  547. Int8: {1, 1, 1},
  548. Interface: {8, 4, 4},
  549. Map: {4, 4, 4},
  550. Pointer: {4, 4, 4},
  551. Slice: {12, 4, 4},
  552. String: {8, 4, 4},
  553. Uint: {4, 4, 4},
  554. Uint16: {2, 2, 2},
  555. Uint32: {4, 4, 4},
  556. Uint64: {8, 4, 4},
  557. Uint8: {1, 1, 1},
  558. Uintptr: {4, 4, 4},
  559. UnsafePointer: {4, 4, 4},
  560. },
  561. // go1.19.1
  562. {"windows", "386"}: {
  563. Bool: {1, 1, 1},
  564. Chan: {4, 4, 4},
  565. Complex128: {16, 4, 4},
  566. Complex64: {8, 4, 4},
  567. Float32: {4, 4, 4},
  568. Float64: {8, 4, 4},
  569. Function: {4, 4, 4},
  570. Int: {4, 4, 4},
  571. Int16: {2, 2, 2},
  572. Int32: {4, 4, 4},
  573. Int64: {8, 4, 4},
  574. Int8: {1, 1, 1},
  575. Interface: {8, 4, 4},
  576. Map: {4, 4, 4},
  577. Pointer: {4, 4, 4},
  578. Slice: {12, 4, 4},
  579. String: {8, 4, 4},
  580. Uint: {4, 4, 4},
  581. Uint16: {2, 2, 2},
  582. Uint32: {4, 4, 4},
  583. Uint64: {8, 4, 4},
  584. Uint8: {1, 1, 1},
  585. Uintptr: {4, 4, 4},
  586. UnsafePointer: {4, 4, 4},
  587. },
  588. // go1.19.1
  589. {"windows", "amd64"}: {
  590. Bool: {1, 1, 1},
  591. Chan: {8, 8, 8},
  592. Complex128: {16, 8, 8},
  593. Complex64: {8, 4, 4},
  594. Float32: {4, 4, 4},
  595. Float64: {8, 8, 8},
  596. Function: {8, 8, 8},
  597. Int: {8, 8, 8},
  598. Int16: {2, 2, 2},
  599. Int32: {4, 4, 4},
  600. Int64: {8, 8, 8},
  601. Int8: {1, 1, 1},
  602. Interface: {16, 8, 8},
  603. Map: {8, 8, 8},
  604. Pointer: {8, 8, 8},
  605. Slice: {24, 8, 8},
  606. String: {16, 8, 8},
  607. Uint: {8, 8, 8},
  608. Uint16: {2, 2, 2},
  609. Uint32: {4, 4, 4},
  610. Uint64: {8, 8, 8},
  611. Uint8: {1, 1, 1},
  612. Uintptr: {8, 8, 8},
  613. UnsafePointer: {8, 8, 8},
  614. },
  615. // go1.19.1
  616. {"windows", "arm64"}: {
  617. Bool: {1, 1, 1},
  618. Chan: {8, 8, 8},
  619. Complex128: {16, 8, 8},
  620. Complex64: {8, 4, 4},
  621. Float32: {4, 4, 4},
  622. Float64: {8, 8, 8},
  623. Function: {8, 8, 8},
  624. Int: {8, 8, 8},
  625. Int16: {2, 2, 2},
  626. Int32: {4, 4, 4},
  627. Int64: {8, 8, 8},
  628. Int8: {1, 1, 1},
  629. Interface: {16, 8, 8},
  630. Map: {8, 8, 8},
  631. Pointer: {8, 8, 8},
  632. Slice: {24, 8, 8},
  633. String: {16, 8, 8},
  634. Uint: {8, 8, 8},
  635. Uint16: {2, 2, 2},
  636. Uint32: {4, 4, 4},
  637. Uint64: {8, 8, 8},
  638. Uint8: {1, 1, 1},
  639. Uintptr: {8, 8, 8},
  640. UnsafePointer: {8, 8, 8},
  641. },
  642. // go1.19.3
  643. {"illumos", "amd64"}: {
  644. Bool: {1, 1, 1},
  645. Chan: {8, 8, 8},
  646. Complex128: {16, 8, 8},
  647. Complex64: {8, 4, 4},
  648. Float32: {4, 4, 4},
  649. Float64: {8, 8, 8},
  650. Function: {8, 8, 8},
  651. Int: {8, 8, 8},
  652. Int16: {2, 2, 2},
  653. Int32: {4, 4, 4},
  654. Int64: {8, 8, 8},
  655. Int8: {1, 1, 1},
  656. Interface: {16, 8, 8},
  657. Map: {8, 8, 8},
  658. Pointer: {8, 8, 8},
  659. Slice: {24, 8, 8},
  660. String: {16, 8, 8},
  661. Uint: {8, 8, 8},
  662. Uint16: {2, 2, 2},
  663. Uint32: {4, 4, 4},
  664. Uint64: {8, 8, 8},
  665. Uint8: {1, 1, 1},
  666. Uintptr: {8, 8, 8},
  667. UnsafePointer: {8, 8, 8},
  668. },
  669. }
  670. )
  671. // ABI describes selected parts of the Application Binary Interface.
  672. type ABI struct {
  673. ByteOrder binary.ByteOrder
  674. goarch string
  675. goos string
  676. Types map[Kind]ABIType
  677. }
  678. type ABIType struct {
  679. Size int64
  680. Align int64
  681. FieldAlign int64
  682. }
  683. // NewABI creates an ABI based on the os+arch pair.
  684. func NewABI(os, arch string) (*ABI, error) {
  685. byteOrder, ok := byteOrders[arch]
  686. if !ok {
  687. return nil, fmt.Errorf("unsupported arch: %s", arch)
  688. }
  689. types0, ok := abiTypes[[2]string{os, arch}]
  690. if !ok {
  691. return nil, fmt.Errorf("unsupported os/arch: %s/%s", os, arch)
  692. }
  693. types := make(map[Kind]ABIType, len(types0))
  694. for k, v := range types0 {
  695. types[k] = v
  696. }
  697. return &ABI{
  698. ByteOrder: byteOrder,
  699. Types: types,
  700. }, nil
  701. }