ld.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Derived from Inferno utils/6l/obj.c and utils/6l/span.c
  2. // https://bitbucket.org/inferno-os/inferno-os/src/master/utils/6l/obj.c
  3. // https://bitbucket.org/inferno-os/inferno-os/src/master/utils/6l/span.c
  4. //
  5. // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
  6. // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
  7. // Portions Copyright © 1997-1999 Vita Nuova Limited
  8. // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
  9. // Portions Copyright © 2004,2006 Bruce Ellis
  10. // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
  11. // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
  12. // Portions Copyright © 2009 The Go Authors. All rights reserved.
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining a copy
  15. // of this software and associated documentation files (the "Software"), to deal
  16. // in the Software without restriction, including without limitation the rights
  17. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  18. // copies of the Software, and to permit persons to whom the Software is
  19. // furnished to do so, subject to the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be included in
  22. // all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  29. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  30. // THE SOFTWARE.
  31. package obj
  32. /*
  33. * add library to library list.
  34. * srcref: src file referring to package
  35. * objref: object file referring to package
  36. * file: object file, e.g., /home/rsc/go/pkg/container/vector.a
  37. * pkg: package import path, e.g. container/vector
  38. */
  39. const (
  40. LOG = 5
  41. )
  42. func mkfwd(sym *LSym) {
  43. var dwn [LOG]int32
  44. var cnt [LOG]int32
  45. var lst [LOG]*Prog
  46. for i := 0; i < LOG; i++ {
  47. if i == 0 {
  48. cnt[i] = 1
  49. } else {
  50. cnt[i] = LOG * cnt[i-1]
  51. }
  52. dwn[i] = 1
  53. lst[i] = nil
  54. }
  55. i := 0
  56. for p := sym.Func.Text; p != nil && p.Link != nil; p = p.Link {
  57. i--
  58. if i < 0 {
  59. i = LOG - 1
  60. }
  61. p.Forwd = nil
  62. dwn[i]--
  63. if dwn[i] <= 0 {
  64. dwn[i] = cnt[i]
  65. if lst[i] != nil {
  66. lst[i].Forwd = p
  67. }
  68. lst[i] = p
  69. }
  70. }
  71. }
  72. func Appendp(q *Prog, newprog ProgAlloc) *Prog {
  73. p := newprog()
  74. p.Link = q.Link
  75. q.Link = p
  76. p.Pos = q.Pos
  77. return p
  78. }