OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
| 5 # Define the sysroot directory. |
| 6 sysroot = "$root_out_dir/sysroot" |
| 7 |
5 config("fusl_config") { | 8 config("fusl_config") { |
6 cflags = [ | 9 cflags = [ |
7 # Flags from musl | 10 # Flags from musl |
8 "-std=c99", | 11 "-std=c99", |
9 "-ffreestanding", | 12 "-ffreestanding", |
10 "-nostdinc", | 13 "-nostdinc", |
11 | 14 |
12 "-D_XOPEN_SOURCE=700", | 15 "-D_XOPEN_SOURCE=700", |
13 | 16 |
14 "-Wa,--noexecstack", | 17 "-Wa,--noexecstack", |
(...skipping 17 matching lines...) Expand all Loading... |
32 } | 35 } |
33 | 36 |
34 # General includes, these need to come after the arch specific includes. | 37 # General includes, these need to come after the arch specific includes. |
35 # src/internal must come before include. | 38 # src/internal must come before include. |
36 include_dirs += [ | 39 include_dirs += [ |
37 "src/internal", | 40 "src/internal", |
38 "include", | 41 "include", |
39 ] | 42 ] |
40 } | 43 } |
41 | 44 |
| 45 # See the discussion below about what these files are, and their |
| 46 # relationship to other C runtime files. |
42 source_set("crt") { | 47 source_set("crt") { |
43 cflags = [] | 48 cflags = [] |
44 | 49 |
45 configs = [] | 50 configs = [] |
46 configs += [ ":fusl_config" ] | 51 configs += [ ":fusl_config" ] |
47 | 52 |
48 cflags += [ | 53 cflags += [ |
49 "-DCRT", | 54 "-DCRT", |
50 "-fno-stack-protector", | 55 "-fno-stack-protector", |
51 ] | 56 ] |
(...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 "src/unistd/unlinkat.c", | 1465 "src/unistd/unlinkat.c", |
1461 "src/unistd/usleep.c", | 1466 "src/unistd/usleep.c", |
1462 "src/unistd/write.c", | 1467 "src/unistd/write.c", |
1463 "src/unistd/writev.c", | 1468 "src/unistd/writev.c", |
1464 ] | 1469 ] |
1465 | 1470 |
1466 # Arch specific sources. | 1471 # Arch specific sources. |
1467 deps += [ ":libc_${current_cpu}" ] | 1472 deps += [ ":libc_${current_cpu}" ] |
1468 } | 1473 } |
1469 | 1474 |
1470 # Build a sysroot. | 1475 # For simplicity, musl places all its symbols in libc. To support |
1471 sysroot = "${target_out_dir}/sysroot/" | 1476 # linking against e.g. libm, either implicitly or with an explicit -lm |
1472 sysroot_lib_dir = "${sysroot}/usr/lib" | 1477 # flag, we build empty libraries. |
1473 sysroot_include_dir = "${sysroot}/usr/include" | 1478 static_library("libm") { |
| 1479 complete_static_lib = true |
| 1480 } |
1474 | 1481 |
1475 template("copy_objects") { | 1482 template("copy_objects") { |
1476 assert(defined(invoker.input_dir), "input_dir must be defined") | 1483 assert(defined(invoker.input_dir), "input_dir must be defined") |
1477 assert(defined(invoker.output_dir), "output_dir must be defined") | 1484 assert(defined(invoker.output_dir), "output_dir must be defined") |
1478 object_prefix = "" | 1485 object_prefix = "" |
1479 if (defined(invoker.object_prefix)) { | 1486 if (defined(invoker.object_prefix)) { |
1480 object_prefix = invoker.object_prefix | 1487 object_prefix = invoker.object_prefix |
1481 } | 1488 } |
1482 foreach(file, invoker.sources) { | 1489 foreach(file, invoker.sources) { |
1483 copy("copy_${file}") { | 1490 copy("copy_${file}") { |
(...skipping 13 matching lines...) Expand all Loading... |
1497 group(target_name) { | 1504 group(target_name) { |
1498 deps = [ | 1505 deps = [ |
1499 ":crt", | 1506 ":crt", |
1500 ] | 1507 ] |
1501 foreach(file, invoker.sources) { | 1508 foreach(file, invoker.sources) { |
1502 deps += [ ":copy_$file" ] | 1509 deps += [ ":copy_$file" ] |
1503 } | 1510 } |
1504 } | 1511 } |
1505 } | 1512 } |
1506 | 1513 |
| 1514 sysroot_lib_dir = "${sysroot}/usr/lib" |
| 1515 sysroot_include_dir = "${sysroot}/usr/include" |
| 1516 |
1507 copy_objects("copy_crt_objects") { | 1517 copy_objects("copy_crt_objects") { |
1508 sources = [ | 1518 sources = [ |
1509 "Scrt1.o", | 1519 "Scrt1.o", |
1510 "crt1.o", | 1520 "crt1.o", |
1511 "rcrt1.o", | 1521 "rcrt1.o", |
1512 ] | 1522 ] |
1513 object_prefix = "crt." | 1523 object_prefix = "crt." |
1514 input_dir = "crt" | 1524 input_dir = "crt" |
1515 output_dir = "${sysroot_lib_dir}" | 1525 output_dir = "${sysroot_lib_dir}" |
1516 } | 1526 } |
(...skipping 24 matching lines...) Expand all Loading... |
1541 if (current_cpu == "x64") { | 1551 if (current_cpu == "x64") { |
1542 sources = [ | 1552 sources = [ |
1543 "arch/x86_64/bits", | 1553 "arch/x86_64/bits", |
1544 ] | 1554 ] |
1545 } | 1555 } |
1546 outputs = [ | 1556 outputs = [ |
1547 "${sysroot_include_dir}/{{source_name_part}}", | 1557 "${sysroot_include_dir}/{{source_name_part}}", |
1548 ] | 1558 ] |
1549 } | 1559 } |
1550 | 1560 |
1551 copy("copy_libc") { | 1561 copy("copy_libs") { |
1552 deps = [ | 1562 deps = [ |
1553 ":libc", | 1563 ":libc", |
| 1564 ":libm", |
1554 ] | 1565 ] |
1555 sources = [ | 1566 sources = [ |
1556 "${target_out_dir}/libc.a", | 1567 "${target_out_dir}/libc.a", |
| 1568 "${target_out_dir}/libm.a", |
1557 ] | 1569 ] |
1558 outputs = [ | 1570 outputs = [ |
1559 "${sysroot_lib_dir}/libc.a", | 1571 "${sysroot_lib_dir}/{{source_name_part}}.a", |
1560 ] | 1572 ] |
1561 } | 1573 } |
1562 | 1574 |
1563 group("sysroot") { | 1575 group("copy_sysroot") { |
1564 deps = [ | 1576 deps = [ |
1565 ":copy_crt_objects", | 1577 ":copy_crt_objects", |
1566 ":copy_include", | 1578 ":copy_include", |
1567 ":copy_include_bits", | 1579 ":copy_include_bits", |
1568 ":copy_libc", | 1580 ":copy_libs", |
1569 ] | 1581 ] |
1570 if (current_cpu == "x64") { | 1582 if (current_cpu == "x64") { |
1571 deps += [ ":copy_crt_x64_objects" ] | 1583 deps += [ ":copy_crt_x64_objects" ] |
1572 } | 1584 } |
1573 } | 1585 } |
1574 | 1586 |
| 1587 # The crtXXX.o files that are copied elsewhere in this file define |
| 1588 # _start, and the machinery to implement calling into the init and |
| 1589 # fini sections. These things are libc dependent and hence part of |
| 1590 # libc. |
| 1591 # |
| 1592 # Unlike the other crtXXX.o files, crtbegin and crtend, are provided |
| 1593 # by the toolchain, not the libc. So we steal them from the host. |
| 1594 # |
| 1595 # crtbegin and crtend know how to call constructors and destructors. |
| 1596 # |
| 1597 # libgcc provides runtime support, and so also comes from the |
| 1598 # compiler. Things in here are stack unwinding, arithmetic not |
| 1599 # supported on the target architecture, and so on. |
| 1600 # |
| 1601 # The best document I am aware of describing the different variants of |
| 1602 # these files (and crtXXX.o above) is |
| 1603 # https://dev.gentoo.org/~vapier/crt.txt |
| 1604 # |
| 1605 # S and _s mean shared or PIE |
| 1606 # T and _eh mean static |
| 1607 action("finish_sysroot") { |
| 1608 script = "tools/populate_crt.py" |
| 1609 |
| 1610 clang = "//third_party/llvm-build/Release+Asserts/bin/clang" |
| 1611 target = "$sysroot/usr/lib" |
| 1612 |
| 1613 files = [ |
| 1614 "crtbegin.o", |
| 1615 "crtbeginS.o", |
| 1616 "crtbeginT.o", |
| 1617 "crtend.o", |
| 1618 "crtendS.o", |
| 1619 |
| 1620 "libgcc.a", |
| 1621 "libgcc_eh.a", |
| 1622 "libgcc_s.so", |
| 1623 ] |
| 1624 |
| 1625 args = [ |
| 1626 rebase_path(clang), |
| 1627 rebase_path(target), |
| 1628 ] |
| 1629 args += files |
| 1630 |
| 1631 outputs = [ |
| 1632 "$target/crtbegin.o", |
| 1633 "$target/crtbeginSo.o", |
| 1634 "$target/crtbeginT.o", |
| 1635 "$target/crtend.o", |
| 1636 "$target/crtendS.o", |
| 1637 |
| 1638 "$target/libgcc.a", |
| 1639 "$target/libgcc_eh.a", |
| 1640 "$target/libgcc_s.so", |
| 1641 ] |
| 1642 |
| 1643 deps = [ |
| 1644 ":copy_sysroot", |
| 1645 ] |
| 1646 } |
| 1647 |
| 1648 config("sysroot_config") { |
| 1649 rebased_sysroot = rebase_path(sysroot) |
| 1650 |
| 1651 cflags = [ |
| 1652 "--sysroot=$rebased_sysroot", |
| 1653 "-fPIC", |
| 1654 "-static", |
| 1655 ] |
| 1656 |
| 1657 ldflags = [ |
| 1658 "--sysroot=$rebased_sysroot", |
| 1659 "-static", |
| 1660 ] |
| 1661 } |
| 1662 |
| 1663 executable("empty_main") { |
| 1664 configs = [] |
| 1665 configs += [ ":sysroot_config" ] |
| 1666 |
| 1667 sources = [ |
| 1668 "test/empty_main.c", |
| 1669 ] |
| 1670 |
| 1671 deps = [ |
| 1672 ":finish_sysroot", |
| 1673 ] |
| 1674 } |
| 1675 |
1575 group("fusl") { | 1676 group("fusl") { |
1576 deps = [ | 1677 deps = [ |
1577 ":crt", | 1678 ":crt(//build/toolchain/fusl:fusl_$current_cpu)", |
1578 ":libc", | 1679 ":empty_main(//build/toolchain/fusl:fusl_$current_cpu)", |
1579 ":sysroot", | 1680 ":finish_sysroot(//build/toolchain/fusl:fusl_$current_cpu)", |
| 1681 ":libc(//build/toolchain/fusl:fusl_$current_cpu)", |
1580 ] | 1682 ] |
1581 } | 1683 } |
OLD | NEW |