You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

149 lines
4.1 KiB

  1. // Copyright (c) 2014, Google Inc.
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. // This package generates chacha_vec_arm.S from chacha_vec.c.
  15. package main
  16. import (
  17. "bufio"
  18. "bytes"
  19. "os"
  20. "os/exec"
  21. "strings"
  22. )
  23. const defaultCompiler = "/opt/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc"
  24. func main() {
  25. compiler := defaultCompiler
  26. if len(os.Args) > 1 {
  27. compiler = os.Args[1]
  28. }
  29. args := []string{
  30. "-O3",
  31. "-mcpu=cortex-a8",
  32. "-mfpu=neon",
  33. "-fpic",
  34. "-DASM_GEN",
  35. "-I", "../../include",
  36. "-S", "chacha_vec.c",
  37. "-o", "-",
  38. }
  39. output, err := os.OpenFile("chacha_vec_arm.S", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
  40. if err != nil {
  41. panic(err)
  42. }
  43. defer output.Close()
  44. output.WriteString(preamble)
  45. output.WriteString(compiler)
  46. output.WriteString(" ")
  47. output.WriteString(strings.Join(args, " "))
  48. output.WriteString("\n\n#if !defined(OPENSSL_NO_ASM)\n\n")
  49. cmd := exec.Command(compiler, args...)
  50. cmd.Stderr = os.Stderr
  51. asm, err := cmd.StdoutPipe()
  52. if err != nil {
  53. panic(err)
  54. }
  55. if err := cmd.Start(); err != nil {
  56. panic(err)
  57. }
  58. attr28 := []byte(".eabi_attribute 28,")
  59. globalDirective := []byte(".global\t")
  60. newLine := []byte("\n")
  61. attr28Handled := false
  62. scanner := bufio.NewScanner(asm)
  63. for scanner.Scan() {
  64. line := scanner.Bytes()
  65. if bytes.Contains(line, attr28) {
  66. output.WriteString(attr28Block)
  67. attr28Handled = true
  68. continue
  69. }
  70. output.Write(line)
  71. output.Write(newLine)
  72. if i := bytes.Index(line, globalDirective); i >= 0 {
  73. output.Write(line[:i])
  74. output.WriteString(".hidden\t")
  75. output.Write(line[i+len(globalDirective):])
  76. output.Write(newLine)
  77. }
  78. }
  79. if err := scanner.Err(); err != nil {
  80. panic(err)
  81. }
  82. if !attr28Handled {
  83. panic("EABI attribute 28 not seen in processing")
  84. }
  85. if err := cmd.Wait(); err != nil {
  86. panic(err)
  87. }
  88. output.WriteString(trailer)
  89. }
  90. const preamble = `# Copyright (c) 2014, Google Inc.
  91. #
  92. # Permission to use, copy, modify, and/or distribute this software for any
  93. # purpose with or without fee is hereby granted, provided that the above
  94. # copyright notice and this permission notice appear in all copies.
  95. #
  96. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  97. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  98. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  99. # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  100. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  101. # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  102. # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  103. # This file contains a pre-compiled version of chacha_vec.c for ARM. This is
  104. # needed to support switching on NEON code at runtime. If the whole of OpenSSL
  105. # were to be compiled with the needed flags to build chacha_vec.c, then it
  106. # wouldn't be possible to run on non-NEON systems.
  107. #
  108. # This file was generated by chacha_vec_arm_generate.go using the following
  109. # compiler command:
  110. #
  111. # `
  112. const attr28Block = `
  113. # EABI attribute 28 sets whether VFP register arguments were used to build this
  114. # file. If object files are inconsistent on this point, the linker will refuse
  115. # to link them. Thus we report whatever the compiler expects since we don't use
  116. # VFP arguments.
  117. #if defined(__ARM_PCS_VFP)
  118. .eabi_attribute 28, 1
  119. #else
  120. .eabi_attribute 28, 0
  121. #endif
  122. `
  123. const trailer = `
  124. #endif /* !OPENSSL_NO_ASM */
  125. `