diff --git gcc/testsuite/g++.dg/gomp/tls-5.C gcc/testsuite/g++.dg/gomp/tls-5.C
index e83ff1179e6..a1d3120fbfb 100644
--- gcc/testsuite/g++.dg/gomp/tls-5.C
+++ gcc/testsuite/g++.dg/gomp/tls-5.C
@@ -1,6 +1,8 @@
 // The reference temp should be TLS, not normal data.
 // { dg-require-effective-target c++11 }
 // { dg-final { scan-assembler-not "\\.data" { target tls_native
xfail powerpc-*-aix* } } }
+// { dg-final { scan-assembler-symbol-section {^_?ir$} {^\.tbss} } }
+// { dg-final { scan-assembler-symbol-section {^_?_ZGR2ir_$} {^\.tdata} } }

 extern int&& ir;
 #pragma omp threadprivate (ir)
diff --git gcc/testsuite/g++.dg/opt/const4.C gcc/testsuite/g++.dg/opt/const4.C
index 883c24b55fc..51d5313a312 100644
--- gcc/testsuite/g++.dg/opt/const4.C
+++ gcc/testsuite/g++.dg/opt/const4.C
@@ -3,7 +3,8 @@
 // that have it.
 // { dg-do compile }

-const int a[] __attribute__ ((__used__)) = { 0, 1, 2, 3 };
+// { dg-final { scan-assembler-symbol-section {constant_variable}
{^\.(const|rodata)} } }
+const int constant_variable[] __attribute__ ((__used__)) = { 0, 1, 2, 3 };

 // The MMIX port always switches to the .data section at the end of a file.
 // { dg-final { scan-assembler-not "\\.data(?!\\.rel\\.ro)" { xfail
powerpc*-*-aix* mmix-*-* } } }
diff --git gcc/testsuite/gcc.dg/20021029-1.c gcc/testsuite/gcc.dg/20021029-1.c
index f11a6e4a920..c8ae4aa60e2 100644
--- gcc/testsuite/gcc.dg/20021029-1.c
+++ gcc/testsuite/gcc.dg/20021029-1.c
@@ -3,6 +3,7 @@
 /* { dg-do compile { target fpic } } */
 /* { dg-options "-O2 -fpic" } */
 /* { dg-final { scan-assembler-not ".data.rel.ro.local" } } */
+/* { dg-final { scan-assembler-symbol-section {ar} {^\.(const|rodata)} } } */
 /* { dg-require-effective-target label_values } */
 /* { dg-require-effective-target indirect_jumps } */

diff --git gcc/testsuite/gcc.dg/array-quals-1.c
gcc/testsuite/gcc.dg/array-quals-1.c
index 3981c916021..819bd24af76 100644
--- gcc/testsuite/gcc.dg/array-quals-1.c
+++ gcc/testsuite/gcc.dg/array-quals-1.c
@@ -6,26 +6,46 @@
 /* { dg-options "-Wno-discarded-array-qualifiers" } */
 /* The MMIX port always switches to the .data section at the end of a file.  */
 /* { dg-final { scan-assembler-not "\\.data(?!\\.rel\\.ro)" { xfail
powerpc*-*-aix* mmix-*-* x86_64-*-mingw* } } } */
+/* { dg-final { scan-assembler-symbol-section {^_?a$}
{^\.(const|rodata)} } } */
 static const int a[2] = { 1, 2 };
+/* { dg-final { scan-assembler-symbol-section {^_?a1$}
{^\.(const|rodata)} } } */
 const int a1[2] = { 1, 2 };
 typedef const int ci;
+/* { dg-final { scan-assembler-symbol-section {^_?b$}
{^\.(const|rodata)} } } */
 static ci b[2] = { 3, 4 };
+/* { dg-final { scan-assembler-symbol-section {^_?b1$}
{^\.(const|rodata)} } } */
 ci b1[2] = { 3, 4 };
 typedef int ia[2];
+/* { dg-final { scan-assembler-symbol-section {^_?c$}
{^\.(const|rodata)} } } */
 static const ia c = { 5, 6 };
+/* { dg-final { scan-assembler-symbol-section {^_?c1$}
{^\.(const|rodata)} } } */
 const ia c1 = { 5, 6 };
 typedef const int cia[2];
+/* { dg-final { scan-assembler-symbol-section {^_?d$}
{^\.(const|rodata)} } } */
 static cia d = { 7, 8 };
+/* { dg-final { scan-assembler-symbol-section {^_?d1$}
{^\.(const|rodata)} } } */
 cia d1 = { 7, 8 };
+/* { dg-final { scan-assembler-symbol-section {^_?e$}
{^\.(const|rodata)} } } */
 static cia e[2] = { { 1, 2 }, { 3, 4 } };
+/* { dg-final { scan-assembler-symbol-section {^_?e1$}
{^\.(const|rodata)} } } */
 cia e1[2] = { { 1, 2 }, { 3, 4 } };
+/* { dg-final { scan-assembler-symbol-section {^_?p$}
{^\.(const|rodata)} } } */
 void *const p = &a;
+/* { dg-final { scan-assembler-symbol-section {^_?q$}
{^\.(const|rodata)} } } */
 void *const q = &b;
+/* { dg-final { scan-assembler-symbol-section {^_?r$}
{^\.(const|rodata)} } } */
 void *const r = &c;
+/* { dg-final { scan-assembler-symbol-section {^_?s$}
{^\.(const|rodata)} } } */
 void *const s = &d;
+/* { dg-final { scan-assembler-symbol-section {^_?t$}
{^\.(const|rodata)} } } */
 void *const t = &e;
+/* { dg-final { scan-assembler-symbol-section {^_?p1$}
{^\.(const|rodata)} } } */
 void *const p1 = &a1;
+/* { dg-final { scan-assembler-symbol-section {^_?q1$}
{^\.(const|rodata)} } } */
 void *const q1 = &b1;
+/* { dg-final { scan-assembler-symbol-section {^_?r1$}
{^\.(const|rodata)} } } */
 void *const r1 = &c1;
+/* { dg-final { scan-assembler-symbol-section {^_?s1$}
{^\.(const|rodata)} } } */
 void *const s1 = &d1;
+/* { dg-final { scan-assembler-symbol-section {^_?t1$}
{^\.(const|rodata)} } } */
 void *const t1 = &e1;
diff --git gcc/testsuite/gcc.dg/darwin-sections.c
gcc/testsuite/gcc.dg/darwin-sections.c
index 79d48bd7da2..8d3a8f47b20 100644
--- gcc/testsuite/gcc.dg/darwin-sections.c
+++ gcc/testsuite/gcc.dg/darwin-sections.c
@@ -16,7 +16,9 @@ e_s ea;
 /* These should go into .data */
 char a = 0;
 short b = 0;
+/* { dg-final { scan-assembler-symbol-section {^_a$} {\.data} } } */
 /* { dg-final { scan-assembler ".globl _a.*.data.*.space\[\t \]1" } } */
+/* { dg-final { scan-assembler-symbol-section {^_b$} {\.data} } } */
 /* { dg-final { scan-assembler ".globl _b.*.data.*.space\[\t \]2" } } */

 /* These should go into __pu_bssN */
diff --git gcc/testsuite/gcc.dg/pr25376.c gcc/testsuite/gcc.dg/pr25376.c
index 3008b091dc2..25f1b66c9bd 100644
--- gcc/testsuite/gcc.dg/pr25376.c
+++ gcc/testsuite/gcc.dg/pr25376.c
@@ -7,3 +7,4 @@ void simple (void)
 }

 /* { dg-final { scan-assembler "my_named_section" } } */
+/* { dg-final { scan-assembler-symbol-section {simple$}
{^my_named_section$} } } */
diff --git gcc/testsuite/gcc.test-framework/dg-scan-symbol-section-1-exp-F.S
gcc/testsuite/gcc.test-framework/dg-scan-symbol-section-1-exp-F.S
new file mode 100644
index 00000000000..70b69271f8f
--- /dev/null
+++ gcc/testsuite/gcc.test-framework/dg-scan-symbol-section-1-exp-F.S
@@ -0,0 +1,13 @@
+// Test the scan-symbol-section directive.
+// scan-symbol-section should fail with 'FAIL' if a symbol has a different
+// section than expected.
+
+// { dg-do preprocess }
+// { dg-final { scan-symbol-section
"dg-scan-symbol-section-1-exp-F.i" {^_test_symbol_.*$} {nomatch} } }
+// The above assertion should fail with the following messages:
+// FAIL: gcc.test-framework/dg-scan-symbol-section-1-exp-F.S
scan-symbol-section symbol ^_test_symbol_.*$ (found _test_symbol_1)
has section nomatch (found .text)
+// FAIL: gcc.test-framework/dg-scan-symbol-section-1-exp-F.S
scan-symbol-section symbol ^_test_symbol_.*$ (found _test_symbol_2)
has section nomatch (found .data)
+    .text
+_test_symbol_1:
+    .data
+_test_symbol_2:
diff --git gcc/testsuite/gcc.test-framework/dg-scan-symbol-section-2-exp-F.S
gcc/testsuite/gcc.test-framework/dg-scan-symbol-section-2-exp-F.S
new file mode 100644
index 00000000000..01872751d4d
--- /dev/null
+++ gcc/testsuite/gcc.test-framework/dg-scan-symbol-section-2-exp-F.S
@@ -0,0 +1,9 @@
+// Test the scan-symbol-section directive.
+// scan-symbol-section should fail with 'UNSUPPORTED' if a symbol has no
+// associated section.
+
+// { dg-do preprocess }
+// { dg-final { scan-symbol-section
"dg-scan-symbol-section-2-exp-F.i" {^_test_symbol$} {^\.text$} } }
+// The above assertion should fail with the following message:
+// FAIL: gcc.test-framework/dg-scan-symbol-section-2-exp-F.S
scan-symbol-section symbol ^_test_symbol$ (found _test_symbol) has
section ^\\.text$ (no section detected)
+_test_symbol:
diff --git gcc/testsuite/gcc.test-framework/dg-scan-symbol-section-3-exp-F.S
gcc/testsuite/gcc.test-framework/dg-scan-symbol-section-3-exp-F.S
new file mode 100644
index 00000000000..87b09a33948
--- /dev/null
+++ gcc/testsuite/gcc.test-framework/dg-scan-symbol-section-3-exp-F.S
@@ -0,0 +1,10 @@
+// Test the scan-symbol-section directive.
+// scan-symbol-section should fail with 'UNSUPPORTED' if a symbol has no
+// associated section.
+
+// { dg-do preprocess }
+// { dg-final { scan-symbol-section
"dg-scan-symbol-section-3-exp-F.i" {^_test_symbol$} {^\.text$} } }
+// The above assertion should fail with the following message:
+// FAIL: gcc.test-framework/dg-scan-symbol-section-3-exp-F.S
scan-symbol-section symbol ^_test_symbol$ (no symbol detected) has
section ^\\.text$
+    .text
+_test_wrong_symbol:
diff --git gcc/testsuite/gcc.test-framework/dg-scan-symbol-section-exp-P.S
gcc/testsuite/gcc.test-framework/dg-scan-symbol-section-exp-P.S
new file mode 100644
index 00000000000..1166b74b376
--- /dev/null
+++ gcc/testsuite/gcc.test-framework/dg-scan-symbol-section-exp-P.S
@@ -0,0 +1,50 @@
+// Test the scan-symbol-section directive.
+
+// { dg-do preprocess }
+
+// The .section directive changes the section for all following symbols.
+    .section .text
+// { dg-final { scan-symbol-section "dg-scan-symbol-section-exp-P.i"
{^_test_function_1$} {^\.text$} } }
+_test_function_1:
+// { dg-final { scan-symbol-section "dg-scan-symbol-section-exp-P.i"
{^_test_function_2$} {^\.text$} } }
+_test_function_2:
+
+// For ELF targets, the .section directive can take multiple arguments.
+    .section .other_text_section,"ax",progbits
+// { dg-final { scan-symbol-section "dg-scan-symbol-section-exp-P.i"
{^_test_elf_function$} {^\.other_text_section$} } }
+_test_elf_function:
+
+// For Mach-O targets, the .section directive takes a segment name
and a section name.
+    .section __TEXT,__my_text_section
+// { dg-final { scan-symbol-section "dg-scan-symbol-section-exp-P.i"
{^_test_macho_function$} {^__TEXT,__my_text_section$} } }
+_test_macho_function:
+// Extra whitespace between .section arguments should be ignored.
+    .section  __DATA , __testsection
+// { dg-final { scan-symbol-section "dg-scan-symbol-section-exp-P.i"
{^_test_macho_var$} {^__DATA,__testsection$} } }
+_test_macho_var:
+
+// The .data directive sets the section for all following symbols to '.data'.
+// { dg-final { scan-symbol-section "dg-scan-symbol-section-exp-P.i"
{^_test_var_1$} {^\.data$} } }
+    .data
+_test_var_1:
+
+// The .text directive sets the section for all following symbols to '.text'.
+// { dg-final { scan-symbol-section "dg-scan-symbol-section-exp-P.i"
{^_test_function_3$} {^\.text$} } }
+    .text
+_test_function_3:
+
+// The .const directive sets the section for all following symbols to '.const'.
+// { dg-final { scan-symbol-section "dg-scan-symbol-section-exp-P.i"
{^_test_data_1$} {^\.const$} } }
+    .const
+_test_data_1:
+
+// Other directives do not affect the section of following symbols.
+// { dg-final { scan-symbol-section "dg-scan-symbol-section-exp-P.i"
{^_test_var_2$} {^\.data$} } }
+    .data
+    .p2align 2
+    .size _test_var_2, 4
+_test_var_2:
+
+// Symbol name patterns can match multiple symbols, and section name patterns
+// can match multiple sections.
+// { dg-final { scan-symbol-section "dg-scan-symbol-section-exp-P.i"
{^_test_function_} {^(\.|__TEXT,).*text} } }
diff --git gcc/testsuite/gcc.test-framework/test-framework.exp
gcc/testsuite/gcc.test-framework/test-framework.exp
index db4b8665258..69a0aca0933 100644
--- gcc/testsuite/gcc.test-framework/test-framework.exp
+++ gcc/testsuite/gcc.test-framework/test-framework.exp
@@ -23,6 +23,7 @@ if { ![info exists env(CHECK_TEST_FRAMEWORK)] } {
 }

 load_lib gcc-dg.exp
+load_lib scanasm.exp

 proc dg-require-true { args } {
     verbose "dg-require-true" 2
@@ -59,7 +60,7 @@ set dg-do-what-default compile
 dg-init

 # Run tests from the source directory.
-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/dg-*.c]] "" ""
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/dg-*.S
$srcdir/$subdir/dg-*.c]] "" ""

 # Skip generated tests unless CHECK_TEST_FRAMEWORK is 1.
 if { $env(CHECK_TEST_FRAMEWORK) != 1 } {
diff --git gcc/testsuite/lib/scanasm.exp gcc/testsuite/lib/scanasm.exp
index 0f1b246b8dc..e9ebf52d77e 100644
--- gcc/testsuite/lib/scanasm.exp
+++ gcc/testsuite/lib/scanasm.exp
@@ -52,10 +52,7 @@ proc dg-scan { name positive testcase output_file
orig_args } {
     set pattern [lindex $orig_args 0]
     set printable_pattern [make_pattern_printable $pattern]

-    if { [is_remote host] } {
-    remote_upload host "$output_file"
-    }
-    set files [glob -nocomplain $output_file]
+    set files [dg_glob_remote $output_file]
     if { $files == "" } {
     verbose -log "$testcase: output file does not exist"
