| ... | ... | @@ -43,6 +43,9 @@ pub fn build(b: *Build) void { |
| 43 | 43 | |
| 44 | 44 | elf_step.dependOn(testAsNeeded(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker })); |
| 45 | 45 | elf_step.dependOn(testCanonicalPlt(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker })); |
| 46 | elf_step.dependOn(testCopyrel(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker })); |
| 47 | elf_step.dependOn(testCopyrelAlias(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker })); |
| 48 | elf_step.dependOn(testCopyrelAlignment(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker })); |
| 46 | 49 | elf_step.dependOn(testDsoPlt(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker })); |
| 47 | 50 | elf_step.dependOn(testDsoUndef(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker })); |
| 48 | 51 | elf_step.dependOn(testLargeAlignmentDso(b, .{ .target = glibc_target, .dynamic_linker = dynamic_linker })); |
| ... | ... | @@ -320,6 +323,152 @@ fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { |
| 320 | 323 | return test_step; |
| 321 | 324 | } |
| 322 | 325 | |
| 326 | fn testCopyrel(b: *Build, opts: Options) *Step { |
| 327 | const test_step = addTestStep(b, "copyrel", opts); |
| 328 | |
| 329 | const dso = addSharedLibrary(b, "a", opts); |
| 330 | addCSourceBytes(dso, |
| 331 | \\int foo = 3; |
| 332 | \\int bar = 5; |
| 333 | , &.{"-fPIC"}); |
| 334 | |
| 335 | const exe = addExecutable(b, "main", opts); |
| 336 | addCSourceBytes(exe, |
| 337 | \\#include<stdio.h> |
| 338 | \\extern int foo, bar; |
| 339 | \\int main() { |
| 340 | \\ printf("%d %d\n", foo, bar); |
| 341 | \\ return 0; |
| 342 | \\} |
| 343 | , &.{}); |
| 344 | exe.linkLibrary(dso); |
| 345 | exe.linkLibC(); |
| 346 | |
| 347 | const run = addRunArtifact(exe); |
| 348 | run.expectStdOutEqual("3 5\n"); |
| 349 | test_step.dependOn(&run.step); |
| 350 | |
| 351 | return test_step; |
| 352 | } |
| 353 | |
| 354 | fn testCopyrelAlias(b: *Build, opts: Options) *Step { |
| 355 | const test_step = addTestStep(b, "copyrel-alias", opts); |
| 356 | |
| 357 | const dso = addSharedLibrary(b, "a", opts); |
| 358 | addCSourceBytes(dso, |
| 359 | \\int bruh = 31; |
| 360 | \\int foo = 42; |
| 361 | \\extern int bar __attribute__((alias("foo"))); |
| 362 | \\extern int baz __attribute__((alias("foo"))); |
| 363 | , &.{"-fPIC"}); |
| 364 | |
| 365 | const exe = addExecutable(b, "main", opts); |
| 366 | addCSourceBytes(exe, |
| 367 | \\#include<stdio.h> |
| 368 | \\extern int foo; |
| 369 | \\extern int *get_bar(); |
| 370 | \\int main() { |
| 371 | \\ printf("%d %d %d\n", foo, *get_bar(), &foo == get_bar()); |
| 372 | \\ return 0; |
| 373 | \\} |
| 374 | , &.{"-fno-PIC"}); |
| 375 | addCSourceBytes(exe, |
| 376 | \\extern int bar; |
| 377 | \\int *get_bar() { return &bar; } |
| 378 | , &.{"-fno-PIC"}); |
| 379 | exe.linkLibrary(dso); |
| 380 | exe.linkLibC(); |
| 381 | exe.pie = false; |
| 382 | |
| 383 | const run = addRunArtifact(exe); |
| 384 | run.expectStdOutEqual("42 42 1\n"); |
| 385 | test_step.dependOn(&run.step); |
| 386 | |
| 387 | return test_step; |
| 388 | } |
| 389 | |
| 390 | fn testCopyrelAlignment(b: *Build, opts: Options) *Step { |
| 391 | const test_step = addTestStep(b, "copyrel-alignment", opts); |
| 392 | |
| 393 | const a_so = addSharedLibrary(b, "a", opts); |
| 394 | addCSourceBytes(a_so, "__attribute__((aligned(32))) int foo = 5;", &.{"-fPIC"}); |
| 395 | |
| 396 | const b_so = addSharedLibrary(b, "b", opts); |
| 397 | addCSourceBytes(b_so, "__attribute__((aligned(8))) int foo = 5;", &.{"-fPIC"}); |
| 398 | |
| 399 | const c_so = addSharedLibrary(b, "c", opts); |
| 400 | addCSourceBytes(c_so, "__attribute__((aligned(256))) int foo = 5;", &.{"-fPIC"}); |
| 401 | |
| 402 | const obj = addObject(b, "main", opts); |
| 403 | addCSourceBytes(obj, |
| 404 | \\#include <stdio.h> |
| 405 | \\extern int foo; |
| 406 | \\int main() { printf("%d\n", foo); } |
| 407 | , &.{"-fno-PIE"}); |
| 408 | obj.linkLibC(); |
| 409 | |
| 410 | const exp_stdout = "5\n"; |
| 411 | |
| 412 | { |
| 413 | const exe = addExecutable(b, "main", opts); |
| 414 | exe.addObject(obj); |
| 415 | exe.linkLibrary(a_so); |
| 416 | exe.linkLibC(); |
| 417 | exe.pie = false; |
| 418 | |
| 419 | const run = addRunArtifact(exe); |
| 420 | run.expectStdOutEqual(exp_stdout); |
| 421 | test_step.dependOn(&run.step); |
| 422 | |
| 423 | const check = exe.checkObject(); |
| 424 | check.checkStart(); |
| 425 | check.checkExact("section headers"); |
| 426 | check.checkExact("name .copyrel"); |
| 427 | check.checkExact("addralign 20"); |
| 428 | test_step.dependOn(&check.step); |
| 429 | } |
| 430 | |
| 431 | { |
| 432 | const exe = addExecutable(b, "main", opts); |
| 433 | exe.addObject(obj); |
| 434 | exe.linkLibrary(b_so); |
| 435 | exe.linkLibC(); |
| 436 | exe.pie = false; |
| 437 | |
| 438 | const run = addRunArtifact(exe); |
| 439 | run.expectStdOutEqual(exp_stdout); |
| 440 | test_step.dependOn(&run.step); |
| 441 | |
| 442 | const check = exe.checkObject(); |
| 443 | check.checkStart(); |
| 444 | check.checkExact("section headers"); |
| 445 | check.checkExact("name .copyrel"); |
| 446 | check.checkExact("addralign 8"); |
| 447 | test_step.dependOn(&check.step); |
| 448 | } |
| 449 | |
| 450 | { |
| 451 | const exe = addExecutable(b, "main", opts); |
| 452 | exe.addObject(obj); |
| 453 | exe.linkLibrary(c_so); |
| 454 | exe.linkLibC(); |
| 455 | exe.pie = false; |
| 456 | |
| 457 | const run = addRunArtifact(exe); |
| 458 | run.expectStdOutEqual(exp_stdout); |
| 459 | test_step.dependOn(&run.step); |
| 460 | |
| 461 | const check = exe.checkObject(); |
| 462 | check.checkStart(); |
| 463 | check.checkExact("section headers"); |
| 464 | check.checkExact("name .copyrel"); |
| 465 | check.checkExact("addralign 100"); |
| 466 | test_step.dependOn(&check.step); |
| 467 | } |
| 468 | |
| 469 | return test_step; |
| 470 | } |
| 471 | |
| 323 | 472 | fn testDsoPlt(b: *Build, opts: Options) *Step { |
| 324 | 473 | const test_step = addTestStep(b, "dso-plt", opts); |
| 325 | 474 | |